Created
August 24, 2016 11:11
-
-
Save izzuddin91/363dfcc475b7c44d2f2c853908c67423 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| Blink | |
| Turns on an LED on for one second, then off for one second, repeatedly. | |
| Most Arduinos have an on-board LED you can control. On the Uno and | |
| Leonardo, it is attached to digital pin 13. If you're unsure what | |
| pin the on-board LED is connected to on your Arduino model, check | |
| the documentation at http://arduino.cc | |
| This example code is in the public domain. | |
| modified 8 May 2014 | |
| by Scott Fitzgerald | |
| */ | |
| int sensorPin = A0; // select the input pin for ldr | |
| int sensorValue = 0; // variable to store the value coming from the sensor | |
| int ledState = LOW; | |
| unsigned long previousMillis = 0; | |
| // constants won't change : | |
| const long interval = 4000; | |
| const long rest = 32400000; | |
| // the setup function runs once when you press reset or power the board | |
| void setup() { | |
| // initialize digital pin 13 as an output. | |
| Serial.begin(9600); | |
| pinMode(13, OUTPUT); | |
| pinMode(12, OUTPUT); | |
| pinMode(11, OUTPUT); | |
| pinMode(10, OUTPUT); | |
| } | |
| // the loop function runs over and over again forever | |
| void loop() { | |
| sensorValue = analogRead(sensorPin); // read the value from the sensor | |
| Serial.println(sensorValue); //prints the values coming from the sensor on the screen | |
| delay(100); | |
| unsigned long currentMillis = millis(); | |
| if (currentMillis - previousMillis >= rest) { | |
| // save the last time you blinked the LED | |
| previousMillis = currentMillis; | |
| // if the LED is off turn it on and vice-versa: | |
| if (ledState == LOW) { | |
| ledState = HIGH; | |
| digitalWrite(13, HIGH); | |
| digitalWrite(12, HIGH); | |
| } | |
| } | |
| Serial.println(ledState); | |
| if (ledState == HIGH){ | |
| if (currentMillis - previousMillis >= interval) { | |
| // save the last time you blinked the LED | |
| previousMillis = currentMillis; | |
| // if the LED is off turn it on and vice-versa: | |
| ledState = LOW; | |
| digitalWrite(13, LOW); | |
| digitalWrite(12, LOW); | |
| } | |
| } | |
| if (sensorValue < 10 ){ | |
| digitalWrite(11, HIGH); | |
| digitalWrite(10, HIGH); | |
| }else{ | |
| digitalWrite(10, LOW); | |
| digitalWrite(11, LOW); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment