Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Timer
- #define delayTime 5
- #define buttonPin A0
- #define signalLedPin 9
- #define pilotLedPin 10
- #define relayPin 11
- unsigned long debounceDelay=50;
- unsigned long longPressDelay=3000; // Long press time
- unsigned long lastDebounceTime1=0;
- unsigned long currentMillis=0, previousMillis=0, previousMillisTimer=0;
- bool readingButton1;
- bool buttonShort1=false;
- bool buttonLong1=false;
- bool buttonShortPress1=false;
- bool buttonLongPress1=false;
- bool reading1=true;
- bool pilotLedStatus=false;
- bool timerStatus=false;
- void setup() {
- Serial.begin(115200);
- Serial.println("Start ...");
- pinMode(buttonPin,INPUT_PULLUP);
- pinMode(signalLedPin,OUTPUT);
- pinMode(pilotLedPin,OUTPUT);
- pinMode(relayPin,OUTPUT);
- }
- void loop() {
- currentMillis = millis();
- if (currentMillis - previousMillis >= 500 and timerStatus==true) {
- previousMillis = currentMillis;
- flash();
- }
- if (currentMillis - previousMillisTimer >= delayTime*1000 and timerStatus==true) {
- previousMillisTimer = currentMillis;
- timerStatus=false;
- digitalWrite(pilotLedPin,LOW);
- digitalWrite(signalLedPin,HIGH);
- digitalWrite(relayPin,HIGH);
- }
- buttonCheck1();
- if (buttonShort1==true and readingButton1==HIGH){
- reading1=false;
- buttonShort1=false;
- Serial.println("Button Short Press");
- digitalWrite(signalLedPin,LOW);
- digitalWrite(relayPin,LOW);
- if (timerStatus==false){
- timerStatus=true;
- previousMillisTimer=millis();;
- } else {
- timerStatus=false;
- digitalWrite(pilotLedPin,LOW);
- }
- }
- if (buttonLong1==true){
- reading1=false;
- buttonLong1=false;
- Serial.println("Button Long Press");
- timerStatus=false;
- digitalWrite(pilotLedPin,LOW);
- digitalWrite(signalLedPin,LOW);
- digitalWrite(relayPin,LOW);
- }
- }
- void flash(){
- if (pilotLedStatus==false){
- pilotLedStatus=true;
- digitalWrite(pilotLedPin,HIGH);
- } else {
- pilotLedStatus=false;
- digitalWrite(pilotLedPin,LOW);
- }
- }
- void buttonCheck1() {
- readingButton1 = digitalRead(buttonPin);
- if (readingButton1==LOW and reading1==true) {
- if ((millis() - lastDebounceTime1) > debounceDelay) {
- buttonShort1=true;
- }
- if ((millis() - lastDebounceTime1) > longPressDelay) {
- buttonLong1=true;
- buttonShort1=false;
- }
- }
- if (readingButton1==HIGH) {
- lastDebounceTime1=millis();
- reading1=true;
- }
- }
- // END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement