Hi
i am working on a arduino project with a group. I was responsible for the physical construction while one of my team mates was responsible for the coding aspect. My team mate has left the course and so i am left to code the box which is due in the next two weeks. While my supervisor has offered full marks on the assignment due to my contribution being complete, i would still like to complete the project.
Because of my low coding skill i was hoping for some help with programming my box.
Part 1
The design of the box is that until the button is pressed nothing happens.
Once the button is held down the program activates.
While the button is pressed the three green and 1 red led light up. If the button is released the green lights will turn off 1 by 1 each second untill only the red is left.
Part 2
Once the red led is left it should start blinking and the arduino should pulse the buzzer until the button is held down.
if the button is held down while the green lights are turning off it should interrupt the program and return to the held state.
with my basic skills i have programmed part 1 but cannot figure out how to get part 2 to work.
i believe i need to use interupts but do not know how to program them.
would someone be able to help?
green leds are 5,6,7
red led is 8
my code is pasted below.
void setup() {
/* Button LED */
pinMode(2, OUTPUT);
/* Button */
pinMode(3, INPUT_PULLUP);
/* LEDs Descending */
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
/* Buzzer */
pinMode(11, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
for (;;) {
if (digitalRead(3) == LOW) {
delay(100);
if (digitalRead(3) == LOW)
break;
}
}
digitalWrite(11, LOW);
digitalWrite(2, LOW);
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);
for (;;) {
if (digitalRead(3) == HIGH) {
delay(100);
if (digitalRead(3) == HIGH)
break;
}
}
for (uint8_t i = 5; i < 8; i++) {
delay(1000);
digitalWrite(i, LOW);
}
digitalWrite(11, HIGH);
}
any help would be greatly appreciated