State Machine & Timing (Graham Widmann)

This week we messed with the space time continuum. Not really, but we did mess with time in our arduino and figured out how to run it effectively with state machines. State machines allow us to control time, sort of. With them we can tell the code to switch to different states and do different things based on what we tell it to do. This is better for us because we do not have to use delay which in more complicated codes will severely impair the functional ability of the arduino. (Basically we will confuse the code). State machines are most easily understood in 3 sections: 1. write out what you want the codes to do physically (turn lights on), 2. read the inputs if there are any, 3. update the state based on inputs and display which state is needed.

We didn’t need to change the board at all, but we did add some different colored LEDs and added the new code once we finished it. The first 2 sections of the code were very easy. All we had to do was tell it directly what we wanted it to do. But in the third section we had to tell it to keep track of time while also doing something else which for some odd reason was the hardest programming challenge I have ever faced. Will and I spent a lot of time in and out of class working on it. We eventually succeeded but not without a lot of help. We had trouble keeping tack of what times would do what and it confused both of us but we eventually gained a better understanding for it. The other problem we has was understanding = vs == which is change this (command) vs compare this  (question).

Another one of the biggest problems we found was understanding that we didn’t need a second state machine for the simple blink faster lights bu this still confuses me a little bit. Dexter helped us understand this because by telling us that all we had to do was tell the button to change a pause in a simple command. From 500 to 200 millis. We made it possible by changing the debounce to read instead of rose. This made it so that it would change only when the button was pressed and held down and not when just pushed. In the void we made, it would change the state of sorts but really only the pause would change with the button. All else was another display state but timing was controlled with the button and the holding of it.

I would show the video but my phone did break and I was not able to retrieve it. If you look at Will Knowlton’s post, he does have the video.




Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s