robosang WROTE:Show some photos of the connection, please. Also the code.
robosang WROTE:Show us what you did, how can we imagine your code?
// Flag needs to be volatile if used in an ISR
volatile int buttonFlag = LOW;
int pin1 = 1;
int pbIn = 0;
int pin3 = 3;
int pin2 = 2;
int pin4 = 4;
void setup ()
{
pinMode(pin1, OUTPUT);
attachInterrupt(pbIn, interruptservice, RISING);
pinMode(pin3, OUTPUT);
pinMode(pin4, OUTPUT);
volatile int buttonFlag = 0;
}
void loop ()
{
if (buttonFlag == LOW)
{
heartbeat (); //make led beat
}
else
{
digitalWrite(pin1, HIGH); //button stays green once pushed
delay (1000); //has some other delays
digitalWrite(pin1, LOW);
delay (1000);
digitalWrite(pin4, HIGH); //button stays green once pushed
delay (1000); //has some other delays
digitalWrite(pin4, LOW);
delay (1000);
buttonFlag = 0; //clear flag after executing code
}
}
void heartbeat ()
{
digitalWrite(pin3, HIGH);
delay(500);
digitalWrite(pin3, LOW);
delay(500);
}
// Interrupt Service Routine attached to INT0 vector
void interruptservice()
{
buttonFlag = digitalRead(pin2); //set flag to value of button
}
Users browsing this forum: No registered users and 39 guests