Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int pin_small_object_green = 7;
- int pin_medium_object_yellow = 8;
- int pin_large_object_red = 9;
- int LDR_input = A0;
- int LDRValue;
- byte time_running = 1;
- int start_time;
- int end_time;
- int duration;
- void setup()
- {
- Serial.begin(9600);
- pinMode(pin_small_object_green, OUTPUT);
- pinMode(pin_medium_object_yellow, OUTPUT);
- pinMode(pin_large_object_red, OUTPUT);
- pinMode(LDR_input, INPUT);
- }
- void loop()
- {
- LDRValue = analogRead(LDR_input);
- if(LDRValue <=700)
- {
- if(time_running == 1)
- {
- time_running = 0;
- start_time = millis()/1000;
- }
- if(time_running == 0)
- {
- end_time = millis()/1000;
- }
- duration = end_time - start_time;
- }
- if(LDRValue >700)
- {
- time_running = 1;
- }
- Serial.println(duration);
- if(duration>0 && duration <=3)
- {
- digitalWrite(pin_small_object_green, HIGH);
- delay(1000);
- digitalWrite(pin_small_object_green, LOW);
- }
- if(duration >3 && duration<=6)
- {
- digitalWrite(pin_medium_object_yellow, HIGH);
- delay(1000);
- digitalWrite(pin_medium_object_yellow, LOW);
- }
- if(duration >6 && duration<=9)
- {
- digitalWrite(pin_large_object_red, HIGH);
- delay(1000);
- digitalWrite(pin_large_object_red, LOW);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement