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)?
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;
}
see the first line, by setting the appropriate value of button numbers, and associtating related interrupting fuctions we can achieve the said functionality
this is simplest code for the said problem, but based on more information enhanced code can be developed.
Get Answers For Free
Most questions answered within 1 hours.