Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Project Name: Arduino Photocell "Conditional Statements"
- Name: Marquessa MacKenzie
- Date: Sept 24th, 2019
- Project: DIGF 2002 - Physical Computing Week Three In-class Assignment
- References:https://www.arduino.cc/reference/en/language/functions/analog-io/analogread/
- https://www.arduino.cc/reference/en/language/functions/analog-io/analogwrite/
- https://www.arduino.cc/reference/en/language/functions/analog-io/analogread/
- */
- void setup() {
- // put your setup code here, to run once:
- Serial.begin(9600); // To run trobleshooting at 9600 baud
- pinMode(11, OUTPUT); //Input to red LED
- pinMode(9, OUTPUT); //Input to yellow LED
- pinMode(6, OUTPUT); //Input to green LED
- }
- void loop() {
- // put your main code here, to run repeatedly:
- Serial.println(analogRead(0)); // To see serial data line for line
- if (analogRead(0) > 700) { // If the serial print line reads greater than 700 then:
- analogWrite (11, 250); // turn the red led on
- analogWrite (9, 0); // turn the yellow led off
- analogWrite (6, 0); // turn the green led off
- } else if (analogRead(0) < 699 && analogRead(0) >= 500) { //If the serial print line reads less than 699 and greater than 500 then:
- analogWrite (11, 0); // turn the red light off
- analogWrite (9, 250); // turn the yellow light on
- analogWrite (6, 0); // turn the green light off
- } else if (analogRead(0) < 500) { //If the serial print line reads less than 500 then:
- analogWrite (11, 0); // turn the red light off
- analogWrite (9, 0); // turn the yellow light off
- analogWrite (6, 250); // turn the green light on
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement