Friday, October 9, 2009

Exercise 2

Exercise 2






I must give credit to Joe Cohen for help with some of this Code.

First, i am setting a variable for timer which is 50, then i am making 2 arrays with alternating pins, making 2 pin counts for each, setting the value for photoPin and photoValue, the next to variables will just be my leds that indicates iether if green is blinking, or if red is blinking. Then analogvalue is set to 0. In the void setup i put a for statement that sais thisPin is 0, less then pin count 1 (3 leds) and adding 1. Then, set the red and green LEDs to output, and then the serial statement. In the void loop, i set photoValue to analog red photoPin whenever it is called. Now is where the magic happens! If photoValue is greater then or equal to 300, for thisPin is 0, greater then pinCount1, and adding 1, then digitalWrite the green pins from 1 to 3, if not then turn them off, also lets print this value. If photoValue is less then 299, for thisPin is pinCount2 -1. and is greater then or equal to 0, subtracting 1 (makes it go the other way), then digitalwrite the YellowPins on a timed sequence called timer. print this. variable ledYellowPin are the red LED pins, yellow was to hard to tell the difference between green in the video. If photo value is greater then or equal to 300, turn green pin on, if not, then shut that off and turn red pin on.



No comments:

Post a Comment