Advertisement
Guest User

Untitled

a guest
Dec 5th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.56 KB | None | 0 0
  1. const int analogPin = 0;
  2. const int ledCount = 10;
  3. int ledPins[]={
  4.   2,3,4,5,6,7,8,9,10,11
  5. };
  6. void setup(){
  7.   for(int thisLed= 0;thisLed<ledCount;thisLed++){
  8.     pinMode(ledPins[thisLed],OUTPUT);
  9.   }
  10. }
  11. void loop(){
  12.   int sensorReading = analogRead(analogPin);
  13.   int ledLevel = map(sensorReading,0,1023,0,ledCount);
  14.  
  15.   for(int thisLed=0;thisLed<ledCount;thisLed++){
  16.     if(thisLed<ledLevel){
  17.       digitalWrite(ledPins[thisLed],HIGH);
  18.     }
  19.     else{
  20.       digitalWrite(ledPins[thisLed],LOW);                                              
  21.     }
  22.   }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement