Advertisement
marquessamackenzie

DIGF 2002 - Arduino Conditional Statements 09/24/19

Sep 24th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. /*
  2. Project Name: Arduino Photocell "Conditional Statements"
  3. Name: Marquessa MacKenzie
  4. Date: Sept 24th, 2019
  5. Project: DIGF 2002 - Physical Computing Week Three In-class Assignment
  6. References:https://www.arduino.cc/reference/en/language/functions/analog-io/analogread/
  7. https://www.arduino.cc/reference/en/language/functions/analog-io/analogwrite/
  8. https://www.arduino.cc/reference/en/language/functions/analog-io/analogread/
  9. */
  10.  
  11.  
  12. void setup() {
  13. // put your setup code here, to run once:
  14. Serial.begin(9600); // To run trobleshooting at 9600 baud
  15. pinMode(11, OUTPUT); //Input to red LED
  16. pinMode(9, OUTPUT); //Input to yellow LED
  17. pinMode(6, OUTPUT); //Input to green LED
  18. }
  19.  
  20. void loop() {
  21. // put your main code here, to run repeatedly:
  22. Serial.println(analogRead(0)); // To see serial data line for line
  23. if (analogRead(0) > 700) { // If the serial print line reads greater than 700 then:
  24. analogWrite (11, 250); // turn the red led on
  25. analogWrite (9, 0); // turn the yellow led off
  26. analogWrite (6, 0); // turn the green led off
  27. } else if (analogRead(0) < 699 && analogRead(0) >= 500) { //If the serial print line reads less than 699 and greater than 500 then:
  28. analogWrite (11, 0); // turn the red light off
  29. analogWrite (9, 250); // turn the yellow light on
  30. analogWrite (6, 0); // turn the green light off
  31. } else if (analogRead(0) < 500) { //If the serial print line reads less than 500 then:
  32. analogWrite (11, 0); // turn the red light off
  33. analogWrite (9, 0); // turn the yellow light off
  34. analogWrite (6, 250); // turn the green light on
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement