Playing with push-button inputs and output LED’s

Hi All,
Could I please get assistance on the following.

There are 3 leds, a buzzer and 3 push-buttons,
button 1, increment leds from left to right and wrap around
button 2, decrement leds from right to left and wrap from last high led
button 3, reset and sound buzzer for long
buzzer, sound everytime button 1 and 2 are pressed.

Challenge: I am not sure as to how I can decrement using button 2 from the last high led.

Code + Format:

// constants won’t change. They’re used here to
// set pin numbers:
const int buttonPin1 = 6; // the number of the pushbutton pin
const int buttonPin2 = 5;
const int buttonPin3 = 2;
const int ledRED = 12;
const int ledBLUE = 10;
const int ledGREEN = 8; // the number of the LED pin
const int buzzer = 4;
int index = -1; // to indicate which led should be turned on

// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
// To save the last logic state of the button
int buttonState2 = 0;

void setup() {
pinMode(ledRED, OUTPUT); // initialize the LEDRED pin as an output
pinMode(ledBLUE, OUTPUT);
pinMode(ledGREEN, OUTPUT);
pinMode(buzzer, OUTPUT); // Set buzzer - pin 4 as an output
pinMode(buttonPin1, INPUT); // initialize the pushbutton pin as an input:
pinMode(buttonPin2, INPUT);
pinMode(buttonPin3, INPUT);
noTone(buzzer); // Stop sound…
digitalWrite(ledRED, HIGH); // On startup led 1, on
}

void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin1);

// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
if (index != -1) { // if index is not the initial value
switch (index) {
case 0:
digitalWrite(ledBLUE, LOW);
digitalWrite(ledRED, LOW);
digitalWrite(buzzer, 0); // Switch pressed, buzzer on
tone(buzzer, 100); // Send 1KHz sound signal…
delay(100); // …for 1 sec
noTone(buzzer); // Stop sound…
break;
case 1:
digitalWrite(ledGREEN, LOW);
digitalWrite(buzzer, 0); // Switch pressed, buzzer on
tone(buzzer, 100); // Send 1KHz sound signal…
delay(100); // …for 1 sec
noTone(buzzer); // Stop sound…
break;
case 2:
digitalWrite(ledRED, LOW);
digitalWrite(buzzer, 0); // Switch pressed, buzzer on
tone(buzzer, 100); // Send 1KHz sound signal…
delay(100); // …for 1 sec
noTone(buzzer); // Stop sound…
break;
}
}

index++; // turn on the next LED
index = index % 3;
switch (index) {
case 0:
digitalWrite(ledBLUE, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(ledRED, LOW);
digitalWrite(buzzer, 0); // Switch pressed, buzzer on
tone(buzzer, 100); // Send 1KHz sound signal…
delay(100); // …for 1 sec
noTone(buzzer); // Stop sound…
break;
case 1:
digitalWrite(ledGREEN, HIGH);
digitalWrite(buzzer, 0); // Switch pressed, buzzer on
tone(buzzer, 100); // Send 1KHz sound signal…
delay(100); // …for 1 sec
noTone(buzzer); // Stop sound…
break;
case 2:
digitalWrite(ledRED, HIGH); // Switch pressed, buzzer on
tone(buzzer, 100); // Send 1KHz sound signal…
delay(100); // …for 1 sec
noTone(buzzer); // Stop sound…
break;
}
}

Please perform Auto-Format on your code, then modify your post above, pasting the formatted code, in code tags.

Thanks PaulRB,
Code Formatted

Switches can bounce when operated, your software can pick up this bounce.
Look at the ‘Change in State’ example and use the technique in your code.

Give us a link to your buzzer.

BTW
delay(100); // …for 1 sec ← - - -<<<< .1 second

Attach your sketch between code tags:
[code]Paste your sketch here[/code]

tone(pin, frequency)
tone(pin, frequency, duration)

dube_ga:
Code Formatted

Don't see any code tags. If you get asked to do anything you don't understand, please ask.

@Paul, not sure how to add code tags (apologies)
@Larry, this buzzer tones on 5V without the code required.

Updated code below
Feedback: code works, however...
Current Challenge: how to use buttonState2 to reverse the led flow
from right to left?

// constants won't change. They're used here to
// set pin numbers:
const int buttonPin1 = 6; // the number of the pushbutton pin
const int buttonPin2 = 5;
const int ResetPin = 1;
const int ledRED = 12;
const int ledBLUE = 10;
const int ledGREEN = 8 ; // the number of the LED pin
const int buzzer = 4;
int index = -1; // to indicate which led should be turned on
int index2 = 0;

// variables will change:
// variable for reading the pushbutton status

int buttonState = 0;
int buttonState2 = 0;
int buttonState3 = 0;

void setup() {
pinMode(ledRED, OUTPUT); // initialize the LEDRED pin as an output
pinMode(ledBLUE, OUTPUT);
pinMode(ledGREEN, OUTPUT);
pinMode(buzzer, OUTPUT); // Set buzzer - pin 4 as an output
pinMode(buttonPin1, INPUT); // initialize the pushbutton pin as an input:
pinMode(buttonPin2, INPUT);
pinMode(ResetPin, INPUT);
noTone(buzzer); // Stop sound...
digitalWrite(ledRED, HIGH); // On startup led 1, on
}

void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin1);

// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) { // button is 1
if(index != -1){ // if index is not the initial value / -1
switch (index){
case 0:
digitalWrite(ledBLUE, LOW);
digitalWrite(ledRED, LOW);
digitalWrite(buzzer,0); // Switch pressed, buzzer on
tone(buzzer, 100); // Send 1KHz sound signal...
delay(100); // ...for 1 sec
noTone(buzzer); // Stop sound...
break;
case 1:
digitalWrite(ledGREEN, LOW);
digitalWrite(buzzer,0); // Switch pressed, buzzer on
tone(buzzer, 100); // Send 1KHz sound signal...
delay(100); // ...for 1 sec
noTone(buzzer); // Stop sound...
break;
case 2:
digitalWrite(ledRED, LOW);
digitalWrite(buzzer,0); // Switch pressed, buzzer on
tone(buzzer, 100); // Send 1KHz sound signal...
delay(100); // ...for 1 sec
noTone(buzzer); // Stop sound...
break;
}//closing switch index
}//closing not equal to if index

index ++; // turn on the next LED
index = index % 3;
switch (index){
case 0:
digitalWrite(ledBLUE, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(ledRED, LOW);
digitalWrite(buzzer,0); // Switch pressed, buzzer on
tone(buzzer, 100); // Send 1KHz sound signal...
delay(100); // ...for 1 sec
noTone(buzzer); // Stop sound...
break;
case 1:
digitalWrite(ledGREEN, HIGH);
digitalWrite(buzzer,0); // Switch pressed, buzzer on
tone(buzzer, 100); // Send 1KHz sound signal...
delay(100); // ...for 1 sec
noTone(buzzer); // Stop sound...
break;
case 2:
digitalWrite(ledRED, HIGH); // Switch pressed, buzzer on
tone(buzzer, 100); // Send 1KHz sound signal...
delay(100); // ...for 1 sec
noTone(buzzer); // Stop sound...
break;
}//closing switch index
}//closing buttonState1

buttonState3 = digitalRead(ResetPin);
if (buttonState3 == LOW) {
digitalWrite(buzzer,0); // Switch pressed, buzzer on
tone(buzzer, 100); // Send 1KHz sound signal...
delay(200); // ...for 1 sec
noTone(buzzer);

}// closing buttonState3

}//closing the void loop

@Paul, not sure how to add code tags (apologies)

Apology not accepted. I said if you were asked to do something you did not understand, then you should ask. You ignored that advice.

Your code defines the reset as pin 1. const int ResetPin = 1;

Pin 1 on an UNO is the TX pin, suggest you use a different pin for this reset.

Code tags:

New people are asked to read:
http://forum.arduino.cc/index.php/topic,148850.0.html

As you had no switch bounce code, made a few changes.

Do you understand why things were added?

Code to reverse the LEDs still needs to be added.

Reset pin is pin 1 :relaxed: BAD

Check if anything is broke:

// constants won't change. They're used here to
// set pin numbers:
const int buttonPin1 = 6;     // the number of the pushbutton pin
const int buttonPin2 = 5;
const int ResetPin   = 1;

const int ledRED     = 12;
const int ledBLUE    = 10;
const int ledGREEN   = 8 ;   // the number of the LED pin

const int buzzer     = 4;    

int index  = -1;             // to indicate which led should be turned on
int index2 = 0;

// variables will change:
// variable for reading the pushbutton status

byte buttonState1     = 0;
byte lastButtonState1 = 0;

byte buttonState2     = 0;
byte lastButtonState2 = 0;

byte buttonState3     = 0;
byte lastButtonState3 = 0;

unsigned long switchMillis;

//*********************************************************************
void setup()
{
  pinMode(ledRED,   OUTPUT);  // initialize the LEDRED pin as an output
  pinMode(ledBLUE,  OUTPUT);
  pinMode(ledGREEN, OUTPUT);
  pinMode(buzzer,   OUTPUT);  // Set buzzer - pin 4 as an output
  pinMode(buttonPin1, INPUT); // initialize the pushbutton pin as an input:
  pinMode(buttonPin2, INPUT);
  pinMode(ResetPin,   INPUT);

  noTone(buzzer);             // Stop sound...

  digitalWrite(ledRED, HIGH); // On startup led 1, on
  
}//closing the void setup()

//*********************************************************************
void loop()
{
  //for debounce, check switches every 50 milli seconds
  if (millis() - switchMillis >= 50)
  {
    switchMillis = millis(); // reset timing
    checkSwitches();
  }

}//closing the void loop()

//*********************************************************************
void checkSwitches()
{
  //***********************************
  // read the state of the pushbutton value:
  buttonState1 = digitalRead(buttonPin1);

  if (lastButtonState1 != buttonState1)
  {
    lastButtonState1 = buttonState1; //update to the new state

    // if it is, the buttonState is HIGH/pressed:
    if (buttonState1 == HIGH)   // button is 1
    {
      // if index is not the initial value / -1
      if (index != -1)
      {
        switch (index)
        {
          case 0:
            digitalWrite(ledBLUE, LOW);
            digitalWrite(ledRED, LOW);
            digitalWrite(buzzer, 0);  // Switch pressed, buzzer on
            tone(buzzer, 100);        // Send 1KHz sound signal...
            delay(100);               // ...for 1 sec
            noTone(buzzer);           // Stop sound...
            break;
            
          case 1:
            digitalWrite(ledGREEN, LOW);
            digitalWrite(buzzer, 0);  // Switch pressed, buzzer on
            tone(buzzer, 100);        // Send 1KHz sound signal...
            delay(100);               // ...for 1 sec
            noTone(buzzer);           // Stop sound...
            break;
            
          case 2:
            digitalWrite(ledRED, LOW);
            digitalWrite(buzzer, 0);  // Switch pressed, buzzer on
            tone(buzzer, 100);        // Send 1KHz sound signal...
            delay(100);               // ...for 1 sec
            noTone(buzzer);           // Stop sound...
            break;

        }//closing switch index

      }//closing not equal to if index

      index ++; // turn on the next LED
      index = index % 3;

      switch (index)
      {
        case 0:
          digitalWrite(ledBLUE, HIGH); // turn the LED on (HIGH is the voltage level)
          digitalWrite(ledRED, LOW);
          digitalWrite(buzzer, 0);  // Switch pressed, buzzer on
          tone(buzzer, 100);        // Send 1KHz sound signal...
          delay(100);               // ...for 1 sec
          noTone(buzzer);           // Stop sound...
          break;
          
        case 1:
          digitalWrite(ledGREEN, HIGH);
          digitalWrite(buzzer, 0);  // Switch pressed, buzzer on
          tone(buzzer, 100);        // Send 1KHz sound signal...
          delay(100);               // ...for 1 sec
          noTone(buzzer);           // Stop sound...
          break;
          
        case 2:
          digitalWrite(ledRED, HIGH);   // Switch pressed, buzzer on
          tone(buzzer, 100);            // Send 1KHz sound signal...
          delay(100);                   // ...for 1 sec
          noTone(buzzer);               // Stop sound...
          break;

      }//closing switch index

    }//closing buttonState1

  }//END of if (lastButtonState != buttonState)

  //***********************************
  buttonState2 = digitalRead(buttonPin2);

  if (lastButtonState2 != buttonState2)
  {
    lastButtonState2 = buttonState2; //update to the new state

    // if it is, the buttonState2 is HIGH/pressed:
    if (buttonState2 == HIGH)   // button is 2
    {
      //do your stuff to reverse the led flow
    }
    
  }//END of if (lastButtonState2 != buttonState2)

  //***********************************
  buttonState3 = digitalRead(ResetPin);

  if (lastButtonState3 != buttonState3)
  {
    lastButtonState3 = buttonState3; //update to the new state

    if (buttonState3 == LOW)
    {
      digitalWrite(buzzer, 0);  // Switch pressed, buzzer on
      tone(buzzer, 100);        // Send 1KHz sound signal...
      delay(200);               // ...for 1 sec
      noTone(buzzer);

    }// closing buttonState3

  }//END of if (lastButtonState3 != buttonState3)

}// closing void checkSwitches()

Why do you have lines 110 thru 136 ?

"this buzzer tones on 5V without the code required."
If are saying 5V across the buzzer makes it beep, don't use tone().
Set a timer for your duration then do a digitalWrite(buzzer, HIGH);
When the timer is over, digitalWrite(buzzer, LOW);

@PaulRB, Im learning, I’m getting there.
@Larry, thanks for the assist, read the guide
New code simulated
Schematic updated and attached
The buzzer I’ll finesse last as it isn’t as prudent as the Led behavior.

Final challenge: reverse LED flow from last active (On) led.
Studied:

/* Objective: increment and decrement leds with wrap using Push-Buttons, Button 1
* increment, Button 2 decrement, Rest button included
* Conditions: sound buzzer on every click of the Push-Button */

// constants won't change. They're used here to set pin numbers:

const int buttonPin1 = 6;     // the number of the pushbutton pin
const int buttonPin2 = 5;
const int ResetPin   = 3;     // this is to reset and sound buzzer twice as long

const int ledRED     = 12;    // the number of the LED pin
const int ledBLUE    = 10;
const int ledGREEN   = 8 ;

const int buzzer     = 4;

int index  = -1;              // to indicate which led should be turned on
int index2 = 0;

// variables will change:
// variable for reading the pushbutton status

byte buttonState1     = 0;
byte lastButtonState1 = 0;

byte buttonState2     = 0;
byte lastButtonState2 = 0;

byte buttonState3     = 0;
byte lastButtonState3 = 0;

unsigned long switchMillis;

//*********************************************************************
void setup()
{
  pinMode(ledRED,   OUTPUT);  // initialize the LEDRED pin as an output
  pinMode(ledBLUE,  OUTPUT);
  pinMode(ledGREEN, OUTPUT);
  pinMode(buzzer,   OUTPUT);  // Set buzzer - pin 4 as an output
  pinMode(buttonPin1, INPUT); // initialize the pushbutton pin as an input:
  pinMode(buttonPin2, INPUT);
  pinMode(ResetPin,   INPUT);

  noTone(buzzer);             // Stop sound...

  digitalWrite(ledRED, HIGH); // On startup first LED must be ON
  
}//closing the void setup()

//*********************************************************************
void loop()
{
  //for debounce, check switches every 50 milli seconds
  if (millis() - switchMillis >= 50)
  {
    switchMillis = millis(); // reset timing
    checkSwitches();
  }

}//closing the void loop()

//*********************************************************************
void checkSwitches()
{
  // ***************************************
  // read the state of the pushbutton value:
  buttonState1 = digitalRead(buttonPin1);

  if (lastButtonState1 != buttonState1) // (!= not equal to)
  {
    lastButtonState1 = buttonState1;    //  update to the new state

    // if it is, the buttonState is HIGH/pressed:
    if (buttonState1 == HIGH)   // button is 1
    {
      // if index is not the initial value / -1
      if (index != -1)
      {
        switch (index)
        {
          case 0:
            digitalWrite(ledBLUE, LOW);
            digitalWrite(ledRED, LOW);
            digitalWrite(buzzer, 0);  // Switch pressed, buzzer on
            tone(buzzer, 100);        // Send 1KHz sound signal...
            delay(100);               // ...for 1 sec
            noTone(buzzer);           // Stop sound...
            break;
            
          case 1:
            digitalWrite(ledGREEN, LOW);
            digitalWrite(buzzer, 0);  // Switch pressed, buzzer on
            tone(buzzer, 100);        // Send 1KHz sound signal...
            delay(100);               // ...for 1 sec
            noTone(buzzer);           // Stop sound...
            break;
            
          case 2:
            digitalWrite(ledRED, LOW);
            digitalWrite(buzzer, 0);  // Switch pressed, buzzer on
            tone(buzzer, 100);        // Send 1KHz sound signal...
            delay(100);               // ...for 1 sec
            noTone(buzzer);           // Stop sound...
            break;

        }//closing switch index

      }//closing not equal to if index

      index ++; // turn on the next LED
      index = index % 3;

      switch (index)
      {
        case 0:
          digitalWrite(ledBLUE, HIGH); // turn the LED on (HIGH is the voltage level)
          digitalWrite(ledRED, LOW);
          digitalWrite(buzzer, 0);  // Switch pressed, buzzer on
          tone(buzzer, 100);        // Send 1KHz sound signal...
          delay(100);               // ...for 1 sec
          noTone(buzzer);           // Stop sound...
          break;
          
        case 1:
          digitalWrite(ledGREEN, HIGH);
          digitalWrite(buzzer, 0);  // Switch pressed, buzzer on
          tone(buzzer, 100);        // Send 1KHz sound signal...
          delay(100);               // ...for 1 sec
          noTone(buzzer);           // Stop sound...
          break;
          
        case 2:
          digitalWrite(ledRED, HIGH);   // Switch pressed, buzzer on
          tone(buzzer, 100);            // Send 1KHz sound signal...
          delay(100);                   // ...for 1 sec
          noTone(buzzer);               // Stop sound...
          break;

      }//closing switch index

    }//closing buttonState1

  }//END of if (lastButtonState != buttonState)

  //***********************************
  buttonState2 = digitalRead(buttonPin2);

  if (lastButtonState2 != buttonState2)
  {
    lastButtonState2 = buttonState2; //update to the new state

    // if it is, the buttonState2 is HIGH/pressed:
    if (buttonState2 == HIGH)   // button is 2
    {
      //do your stuff to reverse the led flow
    }
    
  }//END of if (lastButtonState2 != buttonState2)

  //***********************************
  buttonState3 = digitalRead(ResetPin);

  if (lastButtonState3 != buttonState3)
  {
    lastButtonState3 = buttonState3; //update to the new state

    if (buttonState3 == LOW)
    {
      digitalWrite(buzzer, 0);  // Switch pressed, buzzer on
      tone(buzzer, 100);        // Send 1KHz sound signal...
      delay(200);               // ...for 2 sec, this tone is twice as long
      noTone(buzzer);

    }// closing buttonState3

  }//END of if (lastButtonState3 != buttonState3)

}// closing void checkSwitches()

6615c94215bc2ab8e99f6454da03f2f721cf7700.jpg

Do not connect the ‘Arduino RESET’ to pin 3.

// constants won't change. They're used here to
// set pin numbers:
const byte buttonPin1  = 6;     // the number of the pushbutton pin
const byte buttonPin2  = 5;
const byte ResetPin    = 3;

const byte blockingLED = 13;

const byte ledRED      = 12;
const byte ledBLUE     = 10;
const byte ledGREEN    = 8 ;   // the number of the LED pin

const byte buzzer      = 4;

int index  = 2;                // to indicate which led should be turned on
int index2 = 0;

// variables will change:
// variable for reading the pushbutton status

byte buttonState1     = 0;
byte lastButtonState1 = 0;

byte buttonState2     = 0;
byte lastButtonState2 = 0;

byte buttonStateReset = 0;
byte lastResetState   = 0;

unsigned long switchMillis;
unsigned long blockingMillis;

//*********************************************************************
void setup()
{
  pinMode(blockingLED, OUTPUT);

  pinMode(ledRED,   OUTPUT);  // initialize the LEDRED pin as an output
  digitalWrite(ledRED, HIGH); // On startup led 1, on
  
  pinMode(ledBLUE,  OUTPUT);
  digitalWrite(ledBLUE, LOW); 
  
  pinMode(ledGREEN, OUTPUT);
  digitalWrite(ledGREEN, LOW); 

  pinMode(buzzer,   OUTPUT);  // Set buzzer - pin 4 as an output

  pinMode(buttonPin1, INPUT); // initialize the pushbutton pin as an input:
  lastButtonState1 = digitalRead(buttonPin1);

  pinMode(buttonPin2, INPUT);
  lastButtonState2 = digitalRead(buttonPin2);

  pinMode(ResetPin,   INPUT);
  lastResetState = digitalRead(ResetPin);

  noTone(buzzer);             // Stop sound...

}//closing the void setup()

//*********************************************************************
void loop()
{
  //***********************************
  //Check to see is there is blocking code, blockingLED will normally flash a 1Hz
  if (millis() - blockingMillis >= 500)
  {
    blockingMillis = millis();

    digitalWrite(blockingLED, !digitalRead(blockingLED));
  }

  //***********************************
  //for debounce, check switches every 50 milli seconds
  if (millis() - switchMillis >= 50)
  {
    switchMillis = millis(); // reset timing

    //check the switches
    checkSwitches();
  }

  //***********************************
  //non blocking code goes here
  //***********************************

}//closing the void loop()

//*********************************************************************
void checkSwitches()
{
  //***********************************
  // read the state of the pushbutton value:
  buttonState1 = digitalRead(buttonPin1);

  if (lastButtonState1 != buttonState1)
  {
    lastButtonState1 = buttonState1; //update to the new state

    // if it is, the buttonState is HIGH/pressed:
    if (buttonState1 == HIGH)   // button is 1
    {
      index++;
      if (index > 2)
      {
        index = 0;
      }
      
      switch (index)
      {
        case 0:
          digitalWrite(ledBLUE, HIGH); // turn the LED on (HIGH is the voltage level)
          digitalWrite(ledRED, LOW);
          digitalWrite(ledGREEN, LOW);

          digitalWrite(buzzer, 0);  // Switch pressed, buzzer on
          tone(buzzer, 100);        // Send 1KHz sound signal...
          delay(100);               // ...for 1 sec
          noTone(buzzer);           // Stop sound...

          break;

        case 1:
          digitalWrite(ledBLUE, LOW);
          digitalWrite(ledRED, LOW);
          digitalWrite(ledGREEN, HIGH);

          digitalWrite(buzzer, 0);  // Switch pressed, buzzer on
          tone(buzzer, 100);        // Send 1KHz sound signal...
          delay(100);               // ...for 1 sec
          noTone(buzzer);           // Stop sound...

          break;

        case 2:
          digitalWrite(ledBLUE, LOW);
          digitalWrite(ledRED, HIGH);
          digitalWrite(ledGREEN, LOW);

          tone(buzzer, 100);            // Send 1KHz sound signal...
          delay(100);                   // ...for 1 sec
          noTone(buzzer);               // Stop sound...

          break;

      }//closing switch index

    }//closing buttonState1

  }//END of if (lastButtonState != buttonState)

  //***********************************
  // read the state of the pushbutton value:
  buttonState2 = digitalRead(buttonPin2);

  if (lastButtonState2 != buttonState2)
  {
    lastButtonState2 = buttonState2; //update to the new state

    // if it is, the buttonState2 is HIGH/pressed:
    if (buttonState2 == HIGH)   // button is 2
    {
      index--;
      if (index < 0)
      {
        index = 2;
      }

      switch (index)
      {
        case 0:
          digitalWrite(ledBLUE, HIGH); // turn the LED on (HIGH is the voltage level)
          digitalWrite(ledRED, LOW);
          digitalWrite(ledGREEN, LOW);

          digitalWrite(buzzer, 0);  // Switch pressed, buzzer on
          tone(buzzer, 100);        // Send 1KHz sound signal...
          delay(100);               // ...for 1 sec
          noTone(buzzer);           // Stop sound...

          break;

        case 1:
          digitalWrite(ledBLUE, LOW);
          digitalWrite(ledRED, LOW);
          digitalWrite(ledGREEN, HIGH);

          digitalWrite(buzzer, 0);  // Switch pressed, buzzer on
          tone(buzzer, 100);        // Send 1KHz sound signal...
          delay(100);               // ...for 1 sec
          noTone(buzzer);           // Stop sound...

          break;

        case 2:
          digitalWrite(ledBLUE, LOW);
          digitalWrite(ledRED, HIGH);
          digitalWrite(ledGREEN, LOW);

          tone(buzzer, 100);            // Send 1KHz sound signal...
          delay(100);                   // ...for 1 sec
          noTone(buzzer);               // Stop sound...

          break;

      }//closing switch index

    }//END of if (buttonState2 == HIGH)

  }//END of if (lastButtonState2 != buttonState2)

  //***********************************
  // read the state of the pushbutton value:
  buttonStateReset = digitalRead(ResetPin);

  if (lastResetState != buttonStateReset)
  {
    lastResetState = buttonStateReset; //update to the new state

    if (buttonStateReset == HIGH)
    {
      digitalWrite(buzzer, 0);  // Switch pressed, buzzer on
      tone(buzzer, 100);        // Send 1KHz sound signal...
      delay(200);               // ...for 1 sec
      noTone(buzzer);

    }// closing buttonStateReset

  }//END of if (lastResetState != buttonStateReset)

}// closing void checkSwitches()

//*********************************************************************

What did you want to happen when your breadboard reset switch is closed.

:slight_smile: :slight_smile: :slight_smile:

Thanks Larry, code is working awesomely, I will build it, then attach the final product and update the thread and post to help anyone else.

I honestly can't thank you enough.

  • Do you understand how and why the switches are read every 50 milli seconds?

  • Do you understand what this does?

if (lastButtonState1 != buttonState1)
  {
       . . .
  }
  • Your current 'reset' code doesn't do very much.

  • You still need to address this:
    "this buzzer tones on 5V without the code required."
    If are saying 5V across the buzzer makes it beep, don't use tone().
    Set a timer for your duration then do a digitalWrite(buzzer, HIGH);
    When the timer is over, digitalWrite(buzzer, LOW);

  • Your comments in the sketch need to be reviewed for accuracy

EDIT:
Updated sketch in post #12