Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define heatPin 5
- #define buttonPin1 2
- #define buttonPin2 3
- #define buttonPin3 3
- #define heaterTime1 1000 //en millisecond
- #define heaterTime2 1000 //en millisecond
- #define heaterTime3 1000 //en millisecond
- #define loadTime 1000 //en millisecond
- unsigned long heaterTime1Millis = 0;
- unsigned long heaterTime2Millis = 0;
- unsigned long heaterTime3Millis = 0;
- uint8_t buttonPress = 0 ; //button pressed
- //action for btn 1 pressed
- void actionBtn1Pressed(){
- buttonPress = 1;
- heaterTime1Millis = millis();
- digitalWrite(heatPin, HIGH);
- }
- void actionBtn2Pressed(){
- buttonPress = 2;
- heaterTime2Millis = millis();
- digitalWrite(heatPin, HIGH);
- }
- void actionBtn3Pressed(){
- buttonPress = 3;
- heaterTime3Millis = millis();
- digitalWrite(heatPin, HIGH);
- }
- void endActionButton(){
- buttonPress = 0 ;
- digitalWrite(heatPin, LOW);
- delay(loadTime);
- }
- void setup(){
- pinMode(buttonPin1, INPUT_PULLUP);
- pinMode(buttonPin2, INPUT_PULLUP);
- pinMode(buttonPin3, INPUT_PULLUP);
- pinMode(heatPin, OUTPUT);
- }
- void loop(){
- //!buttonPress -> buttonPress == 0 or buttonPress == false
- if( !digitalRead(buttonPin1) && !buttonPress) actionBtn1Pressed();
- else if( !digitalRead(buttonPin2) && !buttonPress) actionBtn2Pressed();
- else if( !digitalRead(buttonPin3) && !buttonPress) actionBtn3Pressed();
- switch (buttonPress)
- {
- case 1:
- if( (millis() - heaterTime1Millis ) >= heaterTime1){
- //end actionBtn1
- endActionButton();
- }
- break;
- case 2:
- if( (millis() - heaterTime2Millis ) >= heaterTime2){
- //end actionBtn2
- endActionButton();
- }
- break;
- case 3:
- if( (millis() - heaterTime3Millis ) >= heaterTime3){
- //end actionBtn3
- endActionButton();
- }
- break;
- default:
- break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement