Help me to fix this programming and troubleshooting

#include "Arduino.h"
#include "Buzzer.h"
#include "Button.h"

// Pin Definitions
#define BUZZER_PIN_SIG 2
#define IROBJAVOID_PIN_OUT 3
#define PUSHBUTTON_PIN_2 4

// Global variables and defines

// object initialization
Buzzer buzzer(BUZZER_PIN_SIG);
Button pushButton(PUSHBUTTON_PIN_2);

// define vars for testing menu
const int timeout = 10000; //define timeout of 10 sec
char menuOption = 0;
long time0;

// Setup the essentials for your circuit to work. It runs first every time your circuit is powered with electricity.
void setup()
{
// Setup Serial which is useful for debugging
// Use the Serial Monitor to view printed messages
Serial.begin(9600);
while (!Serial) ; // wait for serial port to connect. Needed for native USB
Serial.println("start");

pinMode(IROBJAVOID_PIN_OUT, INPUT);
pushButton.init();
menuOption = menu();

}

// Main logic of your circuit. It defines the interaction between the components you selected. After setup, it runs over and over again, in an eternal loop.
void loop()
{

if(menuOption == '1') {
// Buzzer - Test Code
// The buzzer will turn on and off for 500ms (0.5 sec)
buzzer.on();       // 1. turns on
delay(500);             // 2. waits 500 milliseconds (0.5 sec). Change the value in the brackets (500) for a longer or shorter delay in milliseconds.
buzzer.off();      // 3. turns off.
delay(500);             // 4. waits 500 milliseconds (0.5 sec). Change the value in the brackets (500) for a longer or shorter delay in milliseconds.
}
else if(menuOption == '2') {
// IR Obstacle Avoidance Sensor - Test Code
//Read IR obstacle Sensor. irObjAvoidVar will be '1' if an Obstacle was detected
//Use the onboard trimmer to set the distance of alert
bool irObjAvoidVar = !digitalRead(IROBJAVOID_PIN_OUT);
Serial.print(F("ObjAvoid: ")); Serial.println(irObjAvoidVar);

}
else if(menuOption == '3') {
// Mini Pushbutton Switch - Test Code
//Read pushbutton state. 
//if button is pressed function will return HIGH (1). if not function will return LOW (0). 
//for debounce funtionality try also pushButton.onPress(), .onRelease() and .onChange().
//if debounce is not working properly try changing 'debounceDelay' variable in Button.h
bool pushButtonVal = pushButton.read();
Serial.print(F("Val: ")); Serial.println(pushButtonVal);

}

if (millis() - time0 > timeout)
{
    menuOption = menu();
}

}

// Menu function for selecting the components to be tested
// Follow serial monitor for instrcutions
char menu()
{

Serial.println(F("\nWhich component would you like to test?"));
Serial.println(F("(1) Buzzer"));
Serial.println(F("(2) IR Obstacle Avoidance Sensor"));
Serial.println(F("(3) Mini Pushbutton Switch"));
Serial.println(F("(menu) send anything else or press on board reset button\n"));
while (!Serial.available());

// Read data from serial monitor if received
while (Serial.available()) 
{
    char c = Serial.read();
    if (isAlphaNumeric(c)) 
    {   
        
        if(c == '1') 
      Serial.println(F("Now Testing Buzzer"));
    else if(c == '2') 
      Serial.println(F("Now Testing IR Obstacle Avoidance Sensor"));
    else if(c == '3') 
      Serial.println(F("Now Testing Mini Pushbutton Switch"));
        else
        {
            Serial.println(F("illegal input!"));
            return 0;
        }
        time0 = millis();
        return c;
    }
}

}

Your post was MOVED to it's current location as it is more suitable.

Could you also take a few moments to Learn How To Use The Forum.

Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum in the future.

You need to tell is what the problem is

Please remember to use code tags when posting code

Buzzer.h and Button.h are not standard libraries. If you want anyone to be able to try compiling your sketch it would be helpful to not where you got those libraries.

millis() returns 'unsigned long', not 'long'.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.