top of page
  1. const int RED_PIN = 5;

  2. const int YELLOW_PIN = 3;

  3. const int GREEN_PIN = 4;

  4. const int pot_pin = A0;

  5. int pot_val;

  6.  

  7. void setup() {

  8.   // put your setup code here, to run once:

  9. Serial.begin(9600);

  10. pinMode(RED_PIN, OUTPUT);

  11. pinMode(YELLOW_PIN, OUTPUT);

  12. pinMode(GREEN_PIN, OUTPUT);

  13. }

  14.  

  15. void loop() {

  16.   // put your main code here, to run repeatedly:

  17. pot_val = analogRead(pot_pin);

  18. Serial.println(pot_val);

  19. if(pot_val <= 341){

  20.   digitalWrite(RED_PIN, HIGH);

  21.   digitalWrite(YELLOW_PIN, LOW);

  22.   digitalWrite(GREEN_PIN, LOW);

  23. }

  24. else if(pot_val <= 682){

  25.     digitalWrite(RED_PIN, LOW);

  26.   digitalWrite(YELLOW_PIN, HIGH);

  27.   digitalWrite(GREEN_PIN, LOW);

  28. }

  29. else{

  30.   digitalWrite(RED_PIN, LOW);

  31.   digitalWrite(YELLOW_PIN, LOW);

  32.   digitalWrite(GREEN_PIN, HIGH);

  33.   }

  34.   delay(500);

  35. }

bottom of page