SHARE
TWEET

Untitled

a guest Dec 11th, 2019 97 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //===================== Example1_7 ================================================
  2. #define analogPin  0//connected to analog pin 0
  3. float val= 0; //variable to store the value read
  4. int ledsOn = 0;
  5. void setup(){
  6.    Serial.begin(9600);//setup serial
  7.    pinMode(LED_BUILTIN, OUTPUT);
  8.    }// End of setup function
  9.  
  10. void loop(){
  11.   val=analogRead(analogPin);//read the input pin
  12.   val = val*5/1024; // Analog value
  13.   if (val > 4.65) {
  14.     ledsOn++;
  15.     Serial.println("LED"); // Shows us in console the LED was turned on
  16.     digitalWrite(LED_BUILTIN, HIGH); // Turns LED on
  17.   } else {
  18.     digitalWrite(LED_BUILTIN, LOW); // Turns LED off
  19.   }
  20.  
  21.   if (ledsOn > 0) {
  22.     Serial.println("First LED on"); // Shows us in console the LED was turned on
  23.   }
  24.   if (ledsOn > 1) {
  25.     Serial.println("Second LED on"); // Shows us in console the LED was turned on
  26.   }
  27.   if (ledsOn > 2) {
  28.     Serial.println("Third LED on"); // Shows us in console the LED was turned on
  29.   }
  30.   if (ledsOn > 3) {
  31.     Serial.println("Fourth LED on"); // Shows us in console the LED was turned on
  32.   }
  33.   if (ledsOn > 4) {
  34.     Serial.println("All LEDs turned off"); // Shows us in console the LED was turned on
  35.     ledsOn = 0;
  36.   }
  37.   delay(200);
  38.  }//End of loop function
  39. //============================================================================
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top