Shenzhen I/O: Personal Sandwich Maker

Yeah, this time we are going to make a personal sandwich maker. What could possibly go wrong when making food? Nothing right! This one took me a while to crack, or rather it was fairly easy to make solution. But it took me quite a few tries to make a good one.

The sandwich maker print board have an xbus input where it gets a number from 1 to 3 which is three different modes

  1. Normal sandwich
  2. Hold the cheese
  3. Extra mustard

And the sandwich make then have 5 outputs

  1. bread
  2. meat
  3. cheese
  4. mustard
  5. flag

In case of a normal sandwich we have to activate the following

  1. bread – 1 time unit
  2. meat – 1 time unit
  3. cheese – 1 time unit
  4. mustard – 1 time unit
  5. bread – 1 time unit
  6. flag – 3 time units

There is no pause between the individual outputs. In case of no cheese, we should skip step 3. In case of the extra mustard we should trigger the mustard for 2 time units and then continue. The test cases looks like this

SHENZHEN IO - Personal Sandwich Maker - Signals

Solution to the personal sandwich maker

I started out using 2 micro controllers and a DX300. But I managed to boil it down to 1 MC6000 with a line of code to spare. But it took quite a few iterations. The solution looks like the image below.

SHENZHEN IO - Personal Sandwich Maker - Solution

I will just go through a couple of iterations of the code before coming to the solution, but the layout wont change

Normal sandwich

If we just were to accomplish the first mode the normal sandwich we could write the code as

  slx x1
  tcp x1 2
  gen p1 1 0
  mov 100 x3
  slp 1
  mov 10 x3
  slp 1
  mov 1 x3
  slp 1
  gen p1 1 x3
  gen p0 3 0

Line 2 is only there for us to clear the x1 input so we will go to sleep. Other than that we just go through the whole process one at a time.
Line 10 uses a bit of a trick to remove a line. Originally it would have been the two lines

  mov 0 x3
  gen p1 1 0

However by reading from x3 the output will be reset to 0, and thus we can “cheat” a little bit and thereby skip a line of code. Other than that this is straight forward.

Hold the cheese

Adding the second mode where we skip the cheese, we will modify line 7 and make it two lines, so we only sleep if the x1 is different from 2

  slx x1
  tcp x1 2
  gen p1 1 0
  mov 100 x3
  slp 1
  mov 10 x3
+ slp 1
- slp 1
  mov 1 x3
  slp 1
  gen p1 1 x3
  gen p0 3 0

Extra mustard

Now we only need to be able to add extra mustard. Which happens if x1 is larger than 2. So we can add an extra line of sleep with a + condition and make the code look like

  slx x1
  tcp x1 2
  gen p1 1 0
  mov 100 x3
  slp 1
  mov 10 x3
+ slp 1
- slp 1
  mov 1 x3
  slp 1
+ slp 1
  gen p1 1 x3
  gen p0 3 0

And here we go. Now we can handle all three modes with a result that gives us the following

Cost: 6¥
Energy: 81
Lines of code: 13

Once it was written I must admit that it looks simple, but I had a hard time arriving at that solution. I hope it will inspire you.

Posted by Kristian

Leave a Reply