Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Bounce2.h>
  2. int dataPin = 9;
  3. int latchPin = 10;
  4. int clockPin = 11;
  5. int x, n;
  6. byte conf = 0; // настройка для 1 диода.
  7. int led_conf[8]; // набор настроек для всех диодов.
  8.  
  9. #define pot A0
  10. #define BUTTON 8
  11.  
  12. Bounce bouncer = Bounce(BUTTON,5);
  13. //задаем начальное состояние светодиода "выключен"
  14. int ledValue = LOW;
  15.  
  16. void setup() {
  17.   Serial.begin(9600);
  18.   pinMode(pot, INPUT);
  19.   pinMode(clockPin, OUTPUT);
  20.   pinMode(dataPin, OUTPUT);
  21.   pinMode(latchPin, OUTPUT);
  22.   pinMode(BUTTON,INPUT);
  23.   digitalWrite(latchPin, HIGH);
  24. }
  25.  
  26. void choice(bool mode, int n){
  27.   if (mode == 0){
  28.        
  29.   }else{
  30.    
  31.   }
  32. }
  33.  
  34. void writeLedsData (byte data) {
  35.     digitalWrite(latchPin, LOW);
  36.     shiftOut(dataPin, clockPin, LSBFIRST, data);
  37.     digitalWrite(latchPin, HIGH);
  38. }
  39.  
  40. void handleLeds (byte conf, bool halfBright, byte except) {
  41.   if (millis()%250 < 125 && halfBright == 0){
  42.     sendLedsData(B00000000);
  43.   }else{
  44.     sendLedsData(conf);
  45.   }
  46. }
  47.  
  48. void loop() {
  49.  
  50. //выбор режима и диода.
  51.   x = analogRead(pot) / 4;
  52.   n = map (x, 0, 255, 0, 9);  
  53.     conf = B00000001 << n - 1;// сдвиг влево на 1 бит.
  54.     if ( n == 0){
  55.       handleLeds(B11111111, 1, 0);;
  56.     }else {
  57.      handleLeds(conf, 0, 0);
  58.     }  
  59.    
  60. //алгоритм "отскока кнопки".
  61.  //если сменилось состояние кнопки
  62.  for( n; n <= 9; n++){
  63.   if ( bouncer.update() ) {
  64.     //если считано значение 1
  65.     if ( bouncer.read() == HIGH) {
  66.       //если свет был выключен, будем его включать
  67.      if ( ledValue == LOW ) {
  68.        ledValue = HIGH;
  69.          Serial.println("yes");
  70.      //если свет был включен, будем выключать
  71.      } else {
  72.        ledValue = LOW;
  73.      }  
  74.     }
  75.   }
  76.  }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement