I want to alert myself when a pin changes, and the pin value will change very fast so I am using an interrupt to catch when it changes.
Apparently when you use Serial.println the ISR can't handle it and the program crashes. So how can I alert myself that something took place?
ex: A bullet passes over a IR reciever breaking the IR beam and triggers a change on the GPIO for a couple of milliseconds.
I need to know that the bullet was caught, but it looks like you can't put any real logic inside the ISR, only maybe a state change. The problem is, the state would change again way to fast for any VOID LOOP logic to catch a change was made.
int inPin = 12; // pushbutton connected to digital pin 7
volatile byte state = LOW;
int count = 1;
void setup() {
Serial.begin(115200);
Serial.println("Started");
pinMode(inPin, INPUT); // sets the digital pin 7 as input
attachInterrupt(digitalPinToInterrupt(inPin), blink, CHANGE);
}
void blink() {
state = !state;
Serial.println( "This breaks the code causing a panic.")
}
void loop() {
}
The examples uses this line:
state = !state in the ISR.
I thought that's how you have to handle the change, which would instantly toggle it back and forth, but yes, I can just set it in there and use it elsewhere when I feel like it.