Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int pin_small_object_green = 7;
  2. int pin_medium_object_yellow = 8;
  3. int pin_large_object_red = 9;
  4.  
  5. int LDR_input = A0;
  6.  
  7. int LDRValue;
  8. byte time_running = 1;
  9. int start_time;
  10. int end_time;
  11. int duration;
  12.  
  13.  
  14. void setup()
  15. {
  16.     Serial.begin(9600);
  17.     pinMode(pin_small_object_green, OUTPUT);
  18.     pinMode(pin_medium_object_yellow, OUTPUT);
  19.     pinMode(pin_large_object_red, OUTPUT);
  20.     pinMode(LDR_input, INPUT);
  21.  
  22. }
  23. void loop()
  24. {
  25.     LDRValue = analogRead(LDR_input);
  26.     if(LDRValue <=700)
  27.     {
  28.        if(time_running == 1)
  29.        {
  30.           time_running = 0;
  31.           start_time = millis()/1000;
  32.        }
  33.        if(time_running == 0)
  34.        {
  35.           end_time = millis()/1000;
  36.        }
  37.        duration = end_time - start_time;
  38.     }
  39.     if(LDRValue >700)
  40.     {
  41.         time_running = 1;
  42.     }
  43.     Serial.println(duration);
  44.     if(duration>0 && duration <=3)
  45.     {
  46.         digitalWrite(pin_small_object_green, HIGH);
  47.         delay(1000);
  48.         digitalWrite(pin_small_object_green, LOW);
  49.     }
  50.     if(duration >3 && duration<=6)
  51.     {
  52.         digitalWrite(pin_medium_object_yellow, HIGH);
  53.         delay(1000);
  54.         digitalWrite(pin_medium_object_yellow, LOW);
  55.     }
  56.     if(duration >6 && duration<=9)
  57.     {
  58.         digitalWrite(pin_large_object_red, HIGH);
  59.         delay(1000);
  60.         digitalWrite(pin_large_object_red, LOW);
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement