Errors with .init

I want to make a useless box but everytime I try to verify the code it gives an error. Can anyone help me? Thanks!

Code:
#include <Button.h>

// Include Libraries
#include "Arduino.h"
#include "Servo.h"
#include "Button.h"

// Pin Definitions
#define SERVO360MICRO1_1_PIN_SIG 2
#define SERVO360MICRO2_2_PIN_SIG 3
#define TOGGLESWITCH_PIN_2 4

// Global variables and defines

// object initialization
Servo servo360Micro1_1;
Servo servo360Micro2_2;
Button ToggleSwitch(TOGGLESWITCH_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");

ToggleSwitch.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') {
// Continuous Rotation Micro Servo - FS90R #1 - Test Code
// The servo will rotate CW in full speed, CCW in full speed, and will stop  with an interval of 2000 milliseconds (2 seconds) 
servo360Micro1_1.attach(SERVO360MICRO1_1_PIN_SIG);         // 1. attach the servo to correct pin to control it.
servo360Micro1_1.write(180);  // 2. turns servo CW in full speed. change the value in the brackets (180) to change the speed. As these numbers move closer to 90, the servo will move slower in that direction.
delay(2000);                              // 3. waits 2000 milliseconds (2 sec). change the value in the brackets (2000) for a longer or shorter delay in milliseconds.
servo360Micro1_1.write(0);    // 4. turns servo CCW in full speed. change the value in the brackets (0) to change the speed. As these numbers move closer to 90, the servo will move slower in that direction.
delay(2000);                              // 5. waits 2000 milliseconds (2 sec). change the value in the brackets (2000) for a longer or shorter delay in milliseconds.
servo360Micro1_1.write(90);    // 6. sending 90 stops the servo 
delay(2000);                              // 7. waits 2000 milliseconds (2 sec). change the value in the brackets (2000) for a longer or shorter delay in milliseconds.
servo360Micro1_1.detach();                    // 8. release the servo to conserve power. When detached the servo will NOT hold it's position under stress.
}
else if(menuOption == '2') {
// Continuous Rotation Micro Servo - FS90R #2 - Test Code
// The servo will rotate CW in full speed, CCW in full speed, and will stop  with an interval of 2000 milliseconds (2 seconds) 
servo360Micro2_2.attach(SERVO360MICRO2_2_PIN_SIG);         // 1. attach the servo to correct pin to control it.
servo360Micro2_2.write(180);  // 2. turns servo CW in full speed. change the value in the brackets (180) to change the speed. As these numbers move closer to 90, the servo will move slower in that direction.
delay(2000);                              // 3. waits 2000 milliseconds (2 sec). change the value in the brackets (2000) for a longer or shorter delay in milliseconds.
servo360Micro2_2.write(0);    // 4. turns servo CCW in full speed. change the value in the brackets (0) to change the speed. As these numbers move closer to 90, the servo will move slower in that direction.
delay(2000);                              // 5. waits 2000 milliseconds (2 sec). change the value in the brackets (2000) for a longer or shorter delay in milliseconds.
servo360Micro2_2.write(90);    // 6. sending 90 stops the servo 
delay(2000);                              // 7. waits 2000 milliseconds (2 sec). change the value in the brackets (2000) for a longer or shorter delay in milliseconds.
servo360Micro2_2.detach();                    // 8. release the servo to conserve power. When detached the servo will NOT hold it's position under stress.
}
else if(menuOption == '3') {
// ToggleSwitch - Test Code
//read Toggle Switch state. 
//if Switch is open function will return LOW (0). 
//if it is closed function will return HIGH (1).
bool ToggleSwitchVal = ToggleSwitch.read();
Serial.print(F("Val: ")); Serial.println(ToggleSwitchVal);
}

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

}

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

Serial.println(F("\nWhich component would you like to test?"));
Serial.println(F("(1) Continuous Rotation Micro Servo - FS90R #1"));
Serial.println(F("(2) Continuous Rotation Micro Servo - FS90R #2"));
Serial.println(F("(3) ToggleSwitch"));
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 Continuous Rotation Micro Servo - FS90R #1"));
		else if(c == '2') 
			Serial.println(F("Now Testing Continuous Rotation Micro Servo - FS90R #2"));
		else if(c == '3') 
			Serial.println(F("Now Testing ToggleSwitch"));
        else
        {
            Serial.println(F("illegal input!"));
            return 0;
        }
        time0 = millis();
        return c;
    }
}

}

Error:

C:\Users\lln\AppData\Local\Temp\Temp1_Firmware.zip\Firmware\Firmware.ino: In function 'void setup()':

Firmware:39:18: error: 'class Button' has no member named 'init'

 ToggleSwitch.init();

              ^~~~

Multiple libraries found for "Button.h"

Used: C:\Users\lln\OneDrive\Documents\Arduino\libraries\Button-1.0.0

Unused: C:\Users\lln\OneDrive\Documents\Arduino\libraries\Firmware

Multiple libraries found for "Servo.h"

Used: C:\Users\lln\OneDrive\Documenten\Arduino\libraries\Servo

Unused: C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\libraries\Servo

exit status 1

'class Button' has no member named 'init'

(Note I have downloaded multiple .zip files with button codes).

Hello,
take a view here.

Thanks for the reply, but the problem doesn't lie with the buttons. It's about the .init program that gives the issues.

ok, have a nice day

1 Like

The problem is with the way you use the Button library. Do the examples that come with the library use the init() method? Where did you get the library from?

Can you please edit your post, select all code and click </>; next save the post.

Next please read How to get the best out of this forum (again?).

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