Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //===================== Example1_7 ================================================
- #define analogPin 0//connected to analog pin 0
- float val= 0; //variable to store the value read
- int ledsOn = 0;
- void setup(){
- Serial.begin(9600);//setup serial
- pinMode(LED_BUILTIN, OUTPUT);
- }// End of setup function
- void loop(){
- val=analogRead(analogPin);//read the input pin
- val = val*5/1024; // Analog value
- if (val > 4.65) {
- ledsOn++;
- Serial.println("LED"); // Shows us in console the LED was turned on
- digitalWrite(LED_BUILTIN, HIGH); // Turns LED on
- } else {
- digitalWrite(LED_BUILTIN, LOW); // Turns LED off
- }
- if (ledsOn > 0) {
- Serial.println("First LED on"); // Shows us in console the LED was turned on
- }
- if (ledsOn > 1) {
- Serial.println("Second LED on"); // Shows us in console the LED was turned on
- }
- if (ledsOn > 2) {
- Serial.println("Third LED on"); // Shows us in console the LED was turned on
- }
- if (ledsOn > 3) {
- Serial.println("Fourth LED on"); // Shows us in console the LED was turned on
- }
- if (ledsOn > 4) {
- Serial.println("All LEDs turned off"); // Shows us in console the LED was turned on
- ledsOn = 0;
- }
- delay(200);
- }//End of loop function
- //============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement