Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Bounce2.h>
- int dataPin = 9;
- int latchPin = 10;
- int clockPin = 11;
- int x, n;
- byte conf = 0; // настройка для 1 диода.
- int led_conf[8]; // набор настроек для всех диодов.
- #define pot A0
- #define BUTTON 8
- Bounce bouncer = Bounce(BUTTON,5);
- //задаем начальное состояние светодиода "выключен"
- int ledValue = LOW;
- void setup() {
- Serial.begin(9600);
- pinMode(pot, INPUT);
- pinMode(clockPin, OUTPUT);
- pinMode(dataPin, OUTPUT);
- pinMode(latchPin, OUTPUT);
- pinMode(BUTTON,INPUT);
- digitalWrite(latchPin, HIGH);
- }
- void choice(bool mode, int n){
- if (mode == 0){
- }else{
- }
- }
- void writeLedsData (byte data) {
- digitalWrite(latchPin, LOW);
- shiftOut(dataPin, clockPin, LSBFIRST, data);
- digitalWrite(latchPin, HIGH);
- }
- void handleLeds (byte conf, bool halfBright, byte except) {
- if (millis()%250 < 125 && halfBright == 0){
- sendLedsData(B00000000);
- }else{
- sendLedsData(conf);
- }
- }
- void loop() {
- //выбор режима и диода.
- x = analogRead(pot) / 4;
- n = map (x, 0, 255, 0, 9);
- conf = B00000001 << n - 1;// сдвиг влево на 1 бит.
- if ( n == 0){
- handleLeds(B11111111, 1, 0);;
- }else {
- handleLeds(conf, 0, 0);
- }
- //алгоритм "отскока кнопки".
- //если сменилось состояние кнопки
- for( n; n <= 9; n++){
- if ( bouncer.update() ) {
- //если считано значение 1
- if ( bouncer.read() == HIGH) {
- //если свет был выключен, будем его включать
- if ( ledValue == LOW ) {
- ledValue = HIGH;
- Serial.println("yes");
- //если свет был включен, будем выключать
- } else {
- ledValue = LOW;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement