const byte TrigPin = 2; // M600 trigger pin number (input)
const byte EyePin = 3; // Photocell pin number (input)
const byte BlowValve = 4; // Blow valve pin number (out)
const byte BlowValveON = 13; // LED in the nano indicating blow valve is ON
volatile bool TriggerState = true;
volatile bool BoardDetected = true;
void setup()
{
// initialize digital pins and serial communication for troubleshooting.
pinMode(TrigPin,INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(TrigPin), LabelRequested,FALLING);
pinMode(EyePin,INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(EyePin), EyeTriggered,FALLING);
attachInterrupt(digitalPinToInterrupt(EyePin), Reset,RISING);
pinMode(BlowValve, OUTPUT);
pinMode(BlowValveON, OUTPUT);
Serial.begin(9600);
}
void loop()
{
//TriggerState = digitalRead(TrigPin); // M600 triggered latch
//BoardDetected = digitalRead(EyePin); // eye saw a board
/*if (TriggerState == LOW) {
if (BoardDetected == LOW) {
delay(10); // delay depends on line speed
digitalWrite(BlowValve, HIGH);
digitalWrite(BlowValveON, HIGH); // LED on the arduino
delay(1000); // delay depends on line speed
digitalWrite(BlowValve, LOW);
digitalWrite(BlowValveON, LOW); // LED on the arduino
TriggerState = HIGH;
BoardDetected = HIGH;
}
}
*/
Serial.print("Trigger:");
Serial.println(String(TriggerState));
//Serial.print(F("Ndetection:"));
//Serial.println(String(nDetection));
//Serial.print("Board detected:");
//Serial.println(BoardDetected);
}
void LabelRequested() {
TriggerState = false;
}
void EyeTriggered() {
BoardDetected = false;
}
void Reset() {
TriggerState = true;
}
the ISR on RISING doesn't work properly.
the same routine is called when the pin goes from high to low (falling!)
any help is appreciated.
Your topic was MOVED to its current forum category which is more appropriate than the original as it has nothing to do with Installation and Troubleshooting of the IDE
Don't think you can attach an interrupt on both FALLING and RISING events, for the same pin.
You can attach on a CHANGE event, then in the interrupt check the pin value to determine whether it was RISING (now HIGH) or FALLING (now LOW).
1 Like
Makes sense, I will try this.
Thanks
It was a denouncing issue, I figured it out and out debouncing logic and it did work out
Thanks
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.