this is code for a beermachine
#include <Servo.h>
#include <LiquidCrystal.h>
Servo myservo;
Servo secondserv0;// create servo object to control a servo
// a maximum of eight servo objects can be created
int pos =0; // variable to store the servo position
const int buttonPin = 7;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int buttonState = 0;
void setup()
{
secondserv0.attach(1);
myservo.attach(0); // attaches the servo on pin 0 to the servo object
secondserv0.write(180);
myservo.write(90);
pinMode(buttonPin, INPUT);
}
void loop()
{
lcd.begin(16, 2);
lcd.print("Beer Machine");
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH){
lcd.clear();
lcd.print("Pouring beer...");
for(pos = 90; pos >= 45; pos -= 1) // goes from 90 to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for(pos = 180; pos >= 90; pos -= 1) // goes from 90 to 180 degrees
{ // in steps of 1 degree.
// 90 degrees is stopped.
secondserv0.write(pos); // rotate servo at speed given by 'angle'
delay(100); // waits 20ms between servo commands
}
{
delay(2000);
}
for(pos = 90; pos < 180; pos += 1)// goes from 180 to 90 degrees
{
secondserv0.write(pos); // rotate at a speed given by 'angle'
}
for(pos = 45; pos < 90; pos += 1)// goes from 180 to 90 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(300); // waits 15ms for the servo to reach the position
}
}else {
}
}