Hello everyone
I currently have this weird issue in my program, and I just can't figure it out. I am using INT0 and INT1 on my Arduino. I have the the internal pull-up resistors turned on at INT0 & INT1. I making use of a push button (connected to INT0 - Pin 2) and smoke sensor (connected to INT1 - Pin 3). The push button has a pull down resistor connected to it. I currently have my interrupt to be triggered when it detects a rising edge (so going from low to high).
Now here is the weird part, when I disconnect the wire at the push button end, the interrupt is triggered (but once in a while it will just switch back, as if the interrupt wasn't triggered), but however when I disconnect the wire at the Arduino header, the interrupt is not triggered. I have tried connecting an external pull up resistor as well but no luck.
What I am trying to achieve is having two push buttons connected, one has a greater priority than the other one, I can get it to successfully override the other push button. However when the push button that is connected to INT0 is disconnected, I want it to change the state of pin 8 and keep it that way.
#include <util/delay.h>
volatile unsigned char LED [] = {8,9};
volatile unsigned char BUTTON [] = {0,5}; // Button[0] interrupt 0 is located on Pin 2
// Pin 5 Push Button 2
unsigned char Smoke_Sensor = 1; // Interrupt 1 located on Pin 3, which is used for Smoke Sensor (MQ-2)
boolean Exit_Switch_Operated = false; // Set Emergency Switch as FALSE (Not Pressed)
// ===========================================================================================
// Setup Routine - Executes only once when reset it pressed/arduino powered for first time
// ===========================================================================================
void setup(){
for (int i = 0; i < 2; i++){
pinMode(BUTTON[i], INPUT);
digitalWrite(BUTTON[i], INPUT_PULLUP); // Turn on internal Pull-Up Resistor
pinMode(LED[i], OUTPUT);
}
pinMode(Smoke_Sensor, INPUT);
pinMode(Smoke_Sensor, HIGH);
attachInterrupt(BUTTON[0], override_delay, RISING); // RISING to trigger when the pin goes from low to high
attachInterrupt(Smoke_Sensor, smoke_override_delay, RISING); // LOW to trigger the interrupt whenever the pin is low
}
// ===========================================================================================
// Main Program - Repeats over and over again
// ===========================================================================================
void loop(){
Exit_Switch_Operated = digitalRead(BUTTON[1]);
delay_ms(50); // Used for debouncing of switch
if (Exit_Switch_Operated == LOW){
digitalWrite(LED[0], LOW);
digitalWrite(LED[1], LOW);
}
else{
delay_ms(3000);
digitalWrite(LED[0], HIGH);
delay_ms(2000);
led_flash();
}
}
// ===========================================================================================
// Interrupt Code
// ===========================================================================================
// Execute this code when external interrupt 0 is activated
void override_delay(){
digitalWrite(LED[0],HIGH);
led_flash();
delay_ms(1000);
}
// Execute this code when external interrupt 1 is activated
void smoke_override_delay(){
digitalWrite(LED[0],HIGH);
digitalWrite(LED[1], HIGH);
delay_ms(1000);
}
// ===========================================================================================
// LED Flash Function
// ===========================================================================================
void led_flash()
{
digitalWrite(LED[1], HIGH);
delay_ms(1000);
digitalWrite(LED[1], LOW);
delay_ms(1000);
}
// ===========================================================================================
// Delay Function
// ===========================================================================================
void delay_ms(unsigned int time)
{
while (time--)
_delay_ms(1);
}
Any suggestions would be greatly appreciated.
Thank you