making a car
have to move the servo with buttons
saying statement cannot...overloaded function
const int button = 2;
const int button2=4;// the number of the pushbutton pin
#include <Servo.h>
Servo servo_1;// the number of the LED pin
// variables will change:
int buttonS = 0;
int buttonS2 =3;// variable for reading the pushbutton status
void setup() {
servo_1.attach(3);
Serial.begin ;
// initialize the LED pin as an output:
// initialize the pushbutton pin as an input:
pinMode(button, INPUT);
pinMode (button2,INPUT);
}
void loop() {
buttonS = digitalRead(button);
buttonS2=digitalRead(button2);
if (buttonS == HIGH) ;
{
// turn LED on:
servo_1.write(45);
}
else {if (buttonS2 ==HIGH);
{servo_1.write(90);}
else servo_1.write (30);
}
}
Line 13 Serial.begin need a baud rate
Line 26 remove the ; from the if statement
Line 33 remove the ; from the if statement
Line 38 is missing an opening curly bracket ({).
This compiles
const int button = 2;
const int button2 = 4; // the number of the pushbutton pin
#include <Servo.h>
Servo servo_1;// the number of the LED pin
// variables will change:
int buttonS = 0;
int buttonS2 = 3; // variable for reading the pushbutton status
void setup() {
servo_1.attach(3);
Serial.begin(9600); // missing baud
// initialize the LED pin as an output:
// initialize the pushbutton pin as an input:
pinMode(button, INPUT);
pinMode (button2, INPUT);
}
void loop() {
buttonS = digitalRead(button);
buttonS2 = digitalRead(button2);
if (buttonS == HIGH) // lose the ;
{
// turn LED on:
servo_1.write(45);
}
else
{
if (buttonS2 == HIGH) // lose the ;
{
servo_1.write(90);
}
else
{ // missing {
servo_1.write (30);
}
}
}
Karma for code tags on first post.
In the future, please include the entire text of the error messages.
THE CODE WORKED OUT BUT THE SERVO IS VIBRATING HELP!!!!
i got the code right:
const int button = 2;
const int button2 = 4; // the number of the pushbutton pin
#include <Servo.h>
Servo servo_1;// the number of the LED pin
// variables will change:
int buttonS = 0;
int buttonS2 = 3; // variable for reading the pushbutton status
void setup() {
servo_1.attach(3);
Serial.begin(9600); // missing baud
// initialize the LED pin as an output:
// initialize the pushbutton pin as an input:
pinMode(button, INPUT);
pinMode (button2, INPUT);
}
void loop() {
buttonS = digitalRead(button);
buttonS2 = digitalRead(button2);
if (buttonS == HIGH) // lose the ;
{
// turn LED on:
servo_1.write(45);
}
else
{
if (buttonS2 == HIGH) // lose the ;
{
servo_1.write(90);
}
else
{ // missing {
servo_1.write (30);
}
}
}
but the servo is vibrating when i click the button
(this code is for moving the servo with push buttons
You are welcome.
You really should have appended this question to your previous post. That keeps everything together. You can request that a moderator merge this post with the other.
How are you powering the servos? Servos need a lot (relatively) of power. Budget at least 1 amp per servo to be on the safe side.
A schematic of your project showing all components with part numbers/values would be helpful.