I am new to Arduino and Programming and need help on interrupts.
My first task is to Write a program to count switch presses (one complete closing and opening of a
switch is one count), and display the count in binary on 4 LEDs. When the
count exceeds 1510 (note that a subscript 10 means that the number is decimal,
so 1510 is 15 in decimal notation) the displayed count must roll over (all LEDs
must go out and the count should begin again at zero).
I also must account for switch bounce by inserting a 50 microsecond delay after reading the switch transition before looking for the next one so that mechanical bounce does not cause a switch transition to be counted multiple times.
Lastly, I must Write an interrupt such that upon a falling edge of a second input (includes another
pushbutton switch), the count displayed on the LEDs will be reversed (i.e. the
count will begin to count down if it were counting up before the interrupt, or
will begin to count up if it were counting down before the interrupt).
My code so far is:
/*
Blink
Turns on an LED on for one second, then off for one second, repeatedly.
This example code is in the public domain.
*/
// variables will change:
int button1 = 1; // variable for reading the pushbutton status
int Led1 = 3; // Pin 3 is defined as LED 1 now
int Led2 = 4; // Pin 4 is defined as LED 2 now
int Led3 = 5; // Pin 5 is defined as LED 3 now
int Led4 = 6; // Pin 6 is defined as LED 4 now
int Initiate = 0;
void setup() {
// initialize the LED pin as an output:
pinMode(button1,INPUT);// the input from button one goes into pin1 on the arduino
pinMode(Led1,OUTPUT);// Pin 3 outputs to LED 1
pinMode(Led2,OUTPUT);// Pin 4 outputs to LED 2
pinMode(Led3,OUTPUT);// Pin 5 outputs to LED 3
pinMode(Led4,OUTPUT);// Pin 6 outputs to LED 4
}
void loop(){
Initiate = digitalRead(button1);
if (Initiate == 1){
digitalWrite(Led1, HIGH);
}
else {
digitalWrite(Led1,LOW);
}
}
Please Help
8) :~