Anda di halaman 1dari 2

# include <Servo.

h>
Servo atas;
int pos1 = 0;
const int tombol1 = 0;
const int tombol2 = 1;
const int tombol3 = 4;
const int tombol4 = 5;
int angkat_auto = 1;
int turun_auto = 1;
int angkat_man = 1;
int turun_man = 1;
void setup()
{
atas.attach(9);
pinMode(tombol1,INPUT);
pinMode(tombol2,INPUT);
pinMode(tombol3,INPUT);
pinMode(tombol4,INPUT);
}
void loop()
{
angkat_auto = digitalRead(tombol1);
turun_auto = digitalRead(tombol2);
angkat_man = digitalRead(tombol3);
turun_man = digitalRead(tombol4);
atas.write(pos1);
bak_angkat_auto();
}
void bak_angkat_auto()
{
if (angkat_auto == LOW){
delay(100);
for(pos1 = 0; pos1 < 60; pos1 += 1)
{
atas.write(pos1);
delay(20);
}
}
if (turun_auto == LOW){
delay(100);
for(pos1 = 60; pos1>=1; pos1-=1)
{
atas.write(pos1);
delay(20);
}
}
}
void bak_angkat_manual()
{
if (angkat_man == LOW){
pos1 ++;
} else if (turun_man == LOW){
pos1 --;}
pos1 = constrain(pos1,0,60);
atas.write(pos1);
delay(20);
}

Anda mungkin juga menyukai