a keďže neviem čo použiť namiesto toho delay tak stále čakám 1s kým môžem znova pridať hlasitosť alebo bassy...
fungovať to nejako musí len neviem ako to naprogramovať, moja veža to tak mala...
pokiaľ som jej napríklad pridal bassy vypísala sa hodnota pre basy a po 3s sa vrátila späť na frekvenciu rádia ale všetky tlačidlá boli aktivne, či zmena vstupu pridanie hlasitosti a podobne, reagovali ihneď a ako keby prerušili ten časovač čo čakal tie 3s a hneď ukazalo napr. zmenu vstupu a tam to tiež čakalo 3s a tiež to bolo hneď aktívne...
Kód: Vybrať všetko
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
long time = 0;
long debounce = 200;
LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
const int encoder_pin_A = 4; // the pin where is PIN A of encoder connected
const int encoder_pin_B = 5; // the pin where is PIN B of encoder connected
const int BASS_UP = 7; // the pin where is Bass button connected
const int BASS_DOWN = 8; // the pin where is Bass button connected
// Variables will change:
int Vol = 50; // counter for the number of button presses
int VolupState = 0; // current state of the button
int lastVolupState = 0; // previous state of the button
int VoldownState = 0;
int lastVoldownState = 0;
int encoder_A_read = LOW; // initializating and setting start value for encoder_A_read
int encoder_A_Laststate = LOW; // initializating and setting start value for encoder_A_Laststate
int encoder_B_read = LOW; // initializating and setting start value for encoder_B_read
int encoder_B_Laststate = LOW; // initializating and setting start value for encoder_B_Laststate
int BASS_UP_State = LOW;
int BASS_DOWN_State = LOW;
int BASS_UP_lastState = LOW;
int BASS_DOWN_lastState = LOW;
int BASS = 0;
void setup() {
// initialize the buttons pin as a input:
pinMode(encoder_pin_A, INPUT_PULLUP); //Set pin encoder_pin_A(7) as input
pinMode(encoder_pin_B, INPUT_PULLUP); //Set pin encoder_pin_B(6) as input
pinMode(BASS_UP, INPUT_PULLUP); //Set pin BASS as input
pinMode(BASS_DOWN, INPUT_PULLUP); //Set pin BASS as input
lcd.begin(16,2);
}
void loop() {
// read the pushbutton input pin:
encoder_A_read = digitalRead(encoder_pin_A);
encoder_B_read = digitalRead(encoder_pin_B);
if (encoder_A_Laststate == LOW && encoder_A_read == HIGH && encoder_B_read == LOW && Vol != 1 && millis() - time > debounce)
{ Vol--;
lcd.clear();
lcd.print("Volume: ");
lcd.print(Vol);
}
else if (encoder_A_Laststate == LOW && encoder_A_read == HIGH && encoder_B_read == LOW && Vol == 1 && millis() - time > debounce)
{ lcd.clear();
lcd.print("Volume:MIN");
}
else{}
if (encoder_B_Laststate == LOW && encoder_B_read == HIGH && encoder_A_read == LOW && Vol !=72 && millis() - time > debounce)
{ Vol++;
lcd.clear();
lcd.print("Volume: ");
lcd.print(Vol);
}
else if (encoder_B_Laststate == LOW && encoder_B_read == HIGH && encoder_A_read == LOW && Vol ==72 && millis() - time > debounce)
{ lcd.clear();
lcd.print("Volume:MAX");
}
else{}
//-----------------------------------------------------------------------------
BASS_UP_State = digitalRead(BASS_UP);
BASS_DOWN_State = digitalRead(BASS_DOWN);
if (BASS_UP_State != BASS_UP_lastState) {
// if the state has changed, increment the counter
if (BASS_UP_State == HIGH && BASS < 10 ) {
BASS ++;
lcd.clear();
lcd.print("BASS: ");
lcd.print(BASS);
delay(1000);
lcd.clear();
lcd.print("Volume: ");
lcd.print(Vol);
}
else if (BASS_UP_State == HIGH && BASS == 10 ) {
lcd.clear();
lcd.print("BASS: MAX");
delay(1000);
lcd.clear();
lcd.print("Volume: ");
lcd.print(Vol);
}
else{}
}
//__________________________________________________________________________________________________________________________
if (BASS_DOWN_State != BASS_DOWN_lastState) {
// if the state has changed, increment the counter
if (BASS_DOWN_State == HIGH && BASS !=0 ) {
BASS --;
lcd.clear();
lcd.print("BASS: ");
lcd.print(BASS);
delay(1000);
lcd.clear();
lcd.print("Volume: ");
lcd.print(Vol);
}
else if (BASS_DOWN_State == HIGH && BASS == 0 ) {
lcd.clear();
lcd.print("BASS: OFF");
delay(1000);
lcd.clear();
lcd.print("Volume: ");
lcd.print(Vol);
}
else{}
}
// save the current state as the last state,
//for next time through the loop
encoder_A_Laststate = encoder_A_read;
encoder_B_Laststate = encoder_B_read;
BASS_UP_lastState = BASS_UP_State;
BASS_DOWN_lastState = BASS_DOWN_State;
}