In C, if you are using interrupts for when a button is pressed, how would you use the value you stored in interrupt 1 when (button 1 was pressed) to interrupt 2 when (button 2 was pressed)?
example,
If I press button 1, and the value I have is 5. How would I transfer the value (v = 5) in interrupt 1 to interrupt 2 when I press the button 2 to place in an equation T = 26 + v and then take the value of T and transfer it to interrupt 1 when I press button 1.
Lets see the answer :-
Lets see program :-
const byte ledPin = 1;
const byte interruptPin = 2;
volatile byte state = LOW;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(interruptPin, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(interruptPin),
blink1, CHANGE);
}
void loop() {
digitalWrite(ledPin, state);
}
void blink1() {
state = !state;
}
From the first line, we can see that by setting the appropriate value of button numbers, and associtating related interrupting fuctions we can achieve the said functionality.
Get Answers For Free
Most questions answered within 1 hours.