/*
Zapojenie s dvojicou tlačidiel a jednou LED diódou.
Jedno tlačidlo zrýchľuje a druhé spomaľuje blikanie.
*/
// Cervene tlacidlo spomaluje diodu o 50ms
// Zelene robi opak - zrychluje o 50ms
//Deklaracia LED + tlacidiel
const int ledPin13 = 13;
const int buttonPin2 = 2;
const int buttonPin3 = 3;
int GreenButton = 0;
int RedButton = 0;
// Rychlost blikanie LED
int speedOfFlashing = 500;
void setup() {
pinMode(buttonPin2, INPUT);
pinMode(buttonPin3, INPUT);
pinMode(ledPin13, OUTPUT);
Serial.begin(9600);
}
void loop() {
// Citanie oboch tlacidiel
if(GreenButton != 1){
GreenButton = digitalRead(buttonPin2);
}
if(RedButton != 1){
RedButton = digitalRead(buttonPin3);
}
if (GreenButton == 0){
GreenButton = 0;
}
else{
GreenButton = 1;
speedOfFlashing += 50;
}
if (RedButton == 0 ){
RedButton = 0;
}
else{
RedButton = 1;
speedOfFlashing -= 50;
}
// Nastavenie LED blikania
digitalWrite(ledPin13, HIGH);
delay(speedOfFlashing / 2);
digitalWrite(ledPin13, LOW);
delay(speedOfFlashing / 2);
// Serial output
Serial.print("RedButton: ");
Serial.print(RedButton);
Serial.print(" | ");
Serial.print("GreenButton: ");
Serial.print(GreenButton);
Serial.print(" | ");
Serial.print("SpeedOfLed: ");
Serial.print(speedOfFlashing);
Serial.println("ms");
}