Assignment 2: Traffic Light

So for Assignment 2, I decided to make a traffic light type thing. It has four states: Red, yellow, green, and off. It automatically changes in the code because of the delay (look below)

Delay working video:

https://photos.app.goo.gl/BcLEGQyPuy652W312

 

So once I got that working, I changed the loop() to get the leds changing according to a push button switch.

arduino_traffic_light_with_button

https://photos.app.goo.gl/PgdjJLKbqnVqxTE53

 

 

 

Project 2 State Machines, Switch/Case, and For () Loops

For this project I utilized my previous configuration and implemented for () loops, switch/case, and a state machine to meet the requirements of this project. My previous code was all about 5 inputs that would turn on a light if pressed in the right order as well as an analog reading from the photo resistor. I proceeded to remove one of the 5 buttons as well as the photo resistor and work from the left over 4 inputs A-D. Since I am new to Arduino coding I did a very simple configuration in which each of the 4 buttons would make the LED behave differently. InputA would make the LED flash rapidly, InputB would make the LED pulse slower, InputC would make the LED fade from off to on, and InputC would make the LED fade to off. I practiced by trying to figure out the statement to fade on and once figured out reversed that to have it fade off and then copy pasted that into my for()loop. The rest of the commands were pretty simple.

Link to video- https://youtu.be/lUm5E2ytEoQ

Project2-20170920T170753Z-001

Assignment 2 – Elton Spektor

My idea for the project came from my prior assignment. I adapted my first assignment to use a potentiometer to control different states of my circuit. First, I needed to find the analogRead range of the potentiometer on the Arduino and then I used that to create 4 different states of LED flashes. As I change the potentiometer’s knob, the LEDs would flash in different sequences. The problem I ran into was trying to use a digital pin with PWM to read the analog input of the potentiometer. It did not work well probably because it is not designed for that. Using an analog pin, it worked well and the coding went smoothly.

Video: https://youtu.be/8wO9_W6Jvp0

Assignment 2 Code

Circuit Drawing Assignment 2

 

Assignment 2: State Machines, switch/case, for() loops

The second assignment is about state machines, switch/case and for() statements.

As before, go through the process of coming up with an idea, planning it, implementing it, then documenting your project. If you are going to post your project to google docs, please make sure the link is sharable with other people.

This assignment can be done using your Arduino circuit for Assignment 1. The requirements are to implement a state machine with at least four states and transition paths between those states. The transition path can be a switch, a photoresistor, a pot, or some other form of input you’ve learned outside of class.  You’re free to use other outputs or make your own switches, there’s also the collection of components in A10.

Your state machine should use switch/case to change state and for() loops to create output.

Document your entire process, from your first idea, the circuits that didn’t work, the changes you made, and what was the final result. In your documentation, ask yourself what you learned, what went wrong, what you’d do differently if you did it a second time.

To submit your project, post a reply with the documentation. Attach a zip file to that post containing your Arduino sketch, a photo of your finished breadboard circuit, and anything else you think is relevant. I’m working on how we can post video to the blog, but for now you could post it to your AFS account and link to that from your submission.

Due 23:59, Monday, 18 September. Let me know ASAP if you have a conflict and will be submitting late, if you talked to me after class please send me email as a reminder.