-
-
Save anonymous/df522b90b4386103faaf52c3e3ab34d2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const int buttonPin = 2; // the number of the pushbutton pin | |
const int staubi = 13; // the number of the LED pin | |
const int nebel = 12; // the number of the pushbutton pin | |
const int vent1 = 6; | |
const int vent2 = 7; | |
volatile int buttonState = 0; // variable for reading the pushbutton status | |
void setup() { | |
pinMode(staubi, OUTPUT); | |
pinMode(buttonPin, INPUT); | |
pinMode(vent1, OUTPUT); | |
pinMode(vent2, OUTPUT); | |
pinMode(nebel, OUTPUT); | |
attachInterrupt(0, pin_ISR, CHANGE); | |
} | |
void pin_ISR() { | |
buttonState = digitalRead(buttonPin); | |
digitalWrite(staubi, buttonState); | |
digitalWrite(nebel, buttonState); | |
} | |
void loop() { | |
digitalWrite(vent1, HIGH); // Vent1 an | |
delay(15000); // 15s einatmen | |
digitalWrite(vent1, LOW); // Vent1 aus | |
delay(3000); // Pause 3s | |
digitalWrite(vent2, HIGH); // Vent2 an | |
delay(15000); // 15s ausatmen | |
digitalWrite(vent2, LOW); // Vent2 aus | |
delay(3000); // Pause 3s | |
} |
My application too is similar to yours, I need the ISR to run as long as the switch is "ON", and should exit, the moment the switch is thrown into "OFF". Still breaking my head.... :)
You need to pull pin 13 up (or down) with a resistor and let the pushbutton switch pull the input down (or up) when it is pressed.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Micky, I too am a learner like you. I am NOT an expert. Somewhere I remember reading that all the parameters that are in ISR should be labelled as volatile. I have not run your code, but can you please try labelling "staubi" and "nebel" as volatile and give it a try ?