Help with arduino interrupts

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 :grin: :disappointed_relieved: :expressionless: 8) :~

Turns on an LED on for one second, then off for one second, repeatedly

How?

When the count exceeds 1510

If you want a subscript, then use a subscript

Why do you think you need interrupts?

This sounds a lot like homework.

the displayed count must roll over (all LEDs must go out and the count should begin again at zero).

With 4 LEDs that will happen naturally there is nothing you need to do to make this happen.

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.

50 microseconds is way too small to be effective for practical debouncing, a more practical time is 20mS. Do not use a delay in the ISR.

My code so far is:

not posted in code tags meaning that you have not read the "how to use this forum sticky" at the start of ALL sections.

thirdblackkey:

void loop(){
  Initiate = digitalRead(button1);
  if (Initiate == 1){
  digitalWrite(Led1, HIGH);
  }
  else {
  digitalWrite(Led1,LOW); 
  }
}

Reduces to:

void loop(){
  Initiate = digitalRead(button1);
  digitalWrite(Led1, Initiate); 
}

Or even:

void loop(){
  digitalWrite(Led1, (digitalRead(button1))); 
}

To read if your button has been pressed and released:

void loop(){
   if(digitalRead(button1)==high){  //has button been pressed?
     delay(50);  //debounce time
     while (digitalRead(button1)==high);  //do nothing until button is released. 
     digitalWrite(Led1, HIGH); 
     delay(1000);  //turn on LED for 1 second
     digitalWrite(Led1, LOW);   //turn off LED
  }  //button not pressed
}

Please read the tutorial on interrupts. Then make some attempt to use them. The original code shows no attempt at addressing the question of interrupts at all.