Kod:
#include <Bounce2.h>
unsigned long aktualnyCzas = 0;
unsigned long czasDrgania = 0;
const int button1a = 0;
const int button1b = 1;
const int ledPin1a = 30;
const int ledPin1b = 31;
bool LED1a = LOW;
bool LED1b = LOW;
unsigned long czasLED1a = 0;
unsigned long czasLED1b = 0;
Bounce p1a = Bounce();
Bounce p1b = Bounce();
const int button6a = 18;
const int button6b = 19;
const int button6c = 20;
const int button6d = 21;
const int button6e = 22;
const int button6f = 23;
const int ledPin6a = 48;
const int ledPin6b = 49;
const int ledPin6c = 50;
const int ledPin6d = 51;
bool LED6a = LOW;
bool LED6b = LOW;
bool LED6c = LOW;
bool LED6d = LOW;
bool LED6e = LOW;
bool LED6f = LOW;
unsigned long czasLED6a = 0;
unsigned long czasLED6b = 0;
unsigned long czasLED6c = 0;
unsigned long czasLED6d = 0;
unsigned long czasLED6e = 0;
unsigned long czasLED6f = 0;
Bounce p6a = Bounce();
Bounce p6b = Bounce();
Bounce p6c = Bounce();
Bounce p6d = Bounce();
Bounce p6e = Bounce();
Bounce p6f = Bounce();
void setup() {
Serial.begin(9600);
pinMode(30, OUTPUT);
digitalWrite(30, LOW);
pinMode(31, OUTPUT);
digitalWrite(31, LOW);
p1a.attach(button1a, INPUT_PULLUP);
p1a.interval(20);
p1b.attach(button1b, INPUT_PULLUP);
p1b.interval(20);
pinMode(48, OUTPUT);
digitalWrite(48, LOW);
pinMode(49, OUTPUT);
digitalWrite(49, LOW);
pinMode(50, OUTPUT);
digitalWrite(50, LOW);
pinMode(51, OUTPUT);
digitalWrite(51, LOW);
p6a.attach(button6a, INPUT_PULLUP);
p6a.interval(20);
p6b.attach(button6b, INPUT_PULLUP);
p6b.interval(20);
p6c.attach(button6c, INPUT_PULLUP);
p6c.interval(20);
p6d.attach(button6d, INPUT_PULLUP);
p6d.interval(20);
p6e.attach(button6e, INPUT_PULLUP);
p6e.interval(20);
p6f.attach(button6f, INPUT_PULLUP);
p6f.interval(20);
}
void loop() {
aktualnyCzas = millis();
p1a.update();
p1b.update();
bool stanP1a = p1a.read();
bool stanP1b = p1b.read();
p6a.update();
p6b.update();
p6c.update();
p6d.update();
p6e.update();
p6f.update();
bool stanP6a = p6a.read();
bool stanP6b = p6b.read();
bool stanP6c = p6c.read();
bool stanP6d = p6d.read();
bool stanP6e = p6e.read();
bool stanP6f = p6f.read();
// 1a
if (p1a.fell() && LED1b == LOW) {
Serial.println("Przycisk 1a");
LED1a = !LED1a;
digitalWrite(30, LED1a);
czasLED1a = aktualnyCzas;
}
if (LED1a){
Serial.println("LED1a");
if (aktualnyCzas - czasLED1a >= 1000UL){
czasLED1a = aktualnyCzas;
digitalWrite(30, LOW);
LED1a = LOW;
}
}
// 1b
if (p1b.fell() && LED1a == LOW) {
Serial.println("Przycisk 1b");
LED1b = !LED1b;
digitalWrite(31, LED1b);
czasLED1b = aktualnyCzas;
}
if (LED1b){
Serial.println("LED1b");
if (aktualnyCzas - czasLED1b >= 1000UL){
czasLED1b = aktualnyCzas;
digitalWrite(31, LOW);
LED1b = LOW;
}
}
// 6c
if (p6c.fell() && LED6d == LOW) {
Serial.println("Przycisk 6c");
LED6c =!LED6c;
digitalWrite(48, LED6c);
czasLED6c = aktualnyCzas;
}
if (LED6c){
Serial.println("LED6c");
if (aktualnyCzas - czasLED6c >= 1000UL){
czasLED6c = aktualnyCzas;
digitalWrite(48, LOW);
LED6c = LOW;
}
}
// 6d
if (p6d.fell() && LED6c == LOW) {
Serial.println("Przycisk 6d");
LED6d =!LED6d;
digitalWrite(49, LED6d);
czasLED6d = aktualnyCzas;
}
if (LED6d){
Serial.println("LED6d");
if (aktualnyCzas - czasLED6d >= 1000UL){
czasLED6d = aktualnyCzas;
digitalWrite(49, LOW);
LED6d = LOW;
}
}
// 6e
if (p6e.fell() && LED6f == LOW) {
Serial.println("PRZYCISK 6e");
LED6e =!LED6e;
digitalWrite(50, LED6e);
czasLED6e = aktualnyCzas;
}
if (LED6e){
Serial.println("LED6e");
if (aktualnyCzas - czasLED6e >= 1000UL){
czasLED6e = aktualnyCzas;
digitalWrite(50, LOW);
LED6e = LOW;
}
}
// 6f
if (p6f.fell() && LED6e == LOW) {
Serial.println("PRZYCISK 6f");
LED6f =!LED6f;
digitalWrite(51, LED6f);
czasLED6f = aktualnyCzas;
}
if (LED6f){
Serial.println("LED6f");
if (aktualnyCzas - czasLED6f >= 1000UL){
czasLED6f = aktualnyCzas;
digitalWrite(51, LOW);
LED6f = LOW;
}
}
}