Skip to content

Instantly share code, notes, and snippets.

/micky.c Secret

Created October 4, 2016 17:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/df522b90b4386103faaf52c3e3ab34d2 to your computer and use it in GitHub Desktop.
Save anonymous/df522b90b4386103faaf52c3e3ab34d2 to your computer and use it in GitHub Desktop.
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
}
@madhavdivya
Copy link

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 ?

@madhavdivya
Copy link

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.... :)

@ddonsbach
Copy link

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