daily pastebin goal
37%
SHARE
TWEET

Untitled

a guest Jan 18th, 2019 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const int LED1 = 2;
  2. const int LED2 = 4;
  3. const int LED3 = 7;
  4. const int LED4 = 8;
  5. const int LED5 = 12;
  6. const int LED6 = 13;
  7.  
  8. const int LEDarray[] = {2,4,7,8,12,13};
  9.  
  10. const int constantInterval = 50;
  11.  
  12. int curLED = 0;             // ledState used to set the LED
  13.  
  14. void setup() {
  15.   Serial.begin(9600);
  16.   pinMode(LED1, OUTPUT);
  17.   pinMode(LED2, OUTPUT);
  18.   pinMode(LED3, OUTPUT);
  19.   pinMode(LED4, OUTPUT);
  20.   pinMode(LED5, OUTPUT);
  21.   pinMode(LED6, OUTPUT);
  22. }
  23.  
  24. void loop() {
  25.   unsigned long currentMillis = millis();
  26.   int input = analogRead(A0);
  27.  
  28.   int interval = constantInterval;
  29.  
  30.   //to balance between left and right side
  31.   if(input < 512){
  32.     interval = constantInterval + input;
  33.   }else{
  34.     interval = 512-(input-512) + constantInterval;
  35.   }
  36.  
  37.   //for debugging purpose (do they affect clock rate?)
  38. //  Serial.println(interval);
  39. //  Serial.println(curLED);
  40.  
  41.   if (currentMillis - previousMillis >= interval) {
  42.     // save the last time you blinked the LED
  43.     previousMillis = currentMillis;
  44.  
  45.     //reset the state
  46.     digitalWrite(LED1, LOW);
  47.     digitalWrite(LED2, LOW);
  48.     digitalWrite(LED3, LOW);
  49.     digitalWrite(LED4, LOW);
  50.     digitalWrite(LED5, LOW);
  51.     digitalWrite(LED6, LOW);
  52.  
  53.     if (input < 512){ //<-- left side
  54.        curLED-=1;
  55.        if (curLED < 0){
  56.           curLED = 5;
  57.     }
  58.     }else{ //<-- right side
  59.       curLED+=1;
  60.       if (curLED > 5){
  61.         curLED = 0;
  62.       }
  63.     }
  64.    
  65.  
  66.     //set the curLED on V1
  67.     digitalWrite(LEDarray[curLED], HIGH);
  68.   }
  69. }
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