Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Repeat Button
- #define buttonStart A3
- unsigned long debounceDelay=50; // the debounce time; increase if the output flickers
- unsigned long longPressDelay=1000; // A gombokhoz tartozó hosszú megnyomás
- unsigned long repeatDelay=400; // A gombokhoz tartozó ismétlődés ideje
- signed long repeatDelayDynamic=400;
- signed long dynamic=10;
- unsigned long lastDebounceTime1=0;
- unsigned long counter=0;
- bool readingButton1, readingButton2, readingButton3, readingButton4, readingButton5;
- bool buttonShort1=false, buttonShort2=false, buttonShort3=false, buttonShort4=false, buttonShort5=false;
- bool buttonLong1=false, buttonLong2=false, buttonLong3=false, buttonLong4=false, buttonLong5=false;
- bool repeat1=false;
- void setup(){
- pinMode(buttonStart, INPUT_PULLUP);
- Serial.begin(115200);
- Serial.println("Start ...");
- }
- void loop(){
- buttonCheck1();
- if (buttonShort1==true and readingButton1==HIGH){
- buttonShort1=false;
- //Serial.println("Start Short Press");
- counter++;
- Serial.println(counter);
- }
- if (buttonLong1==true){
- buttonLong1=false;
- // Serial.println("Start Long Press");
- counter++;
- Serial.println(counter);
- }
- }
- void buttonCheck1() {
- readingButton1 = digitalRead(buttonStart);
- if (readingButton1==LOW){
- if (repeat1==false){
- if ((millis() - lastDebounceTime1) > debounceDelay) {
- buttonShort1=true;
- }
- if ((millis() - lastDebounceTime1) > longPressDelay) {
- //buttonLong1=true;
- buttonShort1=false;
- repeat1=true;
- }
- } //else {
- if (millis()-lastDebounceTime1>repeatDelayDynamic) {
- lastDebounceTime1=millis();
- buttonLong1=true;
- buttonShort1=false;
- repeatDelayDynamic=repeatDelayDynamic-dynamic;
- if (repeatDelayDynamic<10) repeatDelayDynamic=10;
- }
- }
- if (readingButton1==HIGH) {
- lastDebounceTime1=millis();
- repeat1==false;
- repeatDelayDynamic=repeatDelay;
- }
- }
- // END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement