#include
#define lArm 8
#define rArm 5
#define wheel 4
#define wArm 6
#define turner 7
Servo solkol;
Servo sagkol;
Servo teker;
Servo tekerkol;
Servo donduren;
const int solDugme = 12;
const int sagDugme = 13;
int dtime = 10;
int leftbutton =0;
int rightbutton = 0;
int counter = 0;
void setup() {
pinMode(solDugme, OUTPUT);
pinMode(sagDugme, OUTPUT);
Serial.begin(9600);
}
void loop() {
leftbutton = digitalRead(solDugme);
rightbutton = digitalRead(sagDugme);
if(counter == 0) {
defaultPosition();
}
if(counter == 1000) {
counter = 1;
}
if(rightbutton == HIGH) {
attachedAll();
servoTurn(donduren, dtime, 0);
servoTurn(sagkol, dtime, 165);
servoTurn(solkol, dtime, 165);
servoTurn(teker, dtime, 180);
servoTurn(tekerkol, dtime, 5);
servoTurn(teker, dtime, 0);
servoTurn(sagkol, dtime, 90);
servoTurn(donduren, dtime, 20);
servoTurn(tekerkol, dtime, 50);
servoTurn(solkol, dtime, 90);
servoTurn(sagkol, dtime, 165);
servoTurn(donduren, dtime, 180);
servoTurn(solkol, dtime, 165);
servoTurn(tekerkol, dtime, 90);
servoTurn(donduren, dtime, 0);
Serial.println("Left button pressed");
detachAll();
}
if(leftbutton == HIGH) {
attachedAll();
servoTurn(donduren, dtime, 180);
servoTurn(solkol, dtime, 165);
servoTurn(sagkol, dtime, 165);
servoTurn(teker, dtime, 0);
servoTurn(tekerkol, dtime, 150);
servoTurn(solkol, dtime, 90);
servoTurn(teker, dtime, 180);
servoTurn(donduren, dtime, 160);
servoTurn(sagkol, dtime, 90);
servoTurn(tekerkol, dtime, 90);
servoTurn(donduren, dtime, 0);
servoTurn(sagkol, dtime, 165);
servoTurn(solkol, dtime, 165);
servoTurn(donduren, dtime, 180);
Serial.println("Right button pressed");
detachAll();
}
counter++;
}
void defaultPosition() {
attachedAll();
servoTurn(sagkol, dtime, 15);
servoTurn(solkol, dtime, 15);
servoTurn(tekerkol, dtime, 90);
servoTurn(teker, dtime, 0);
servoTurn(donduren, dtime, 0);
Serial.println("Start");
detachAll();
}
void detachAll() {
if(solkol.attached()) solkol.detach();
if(sagkol.attached()) sagkol.detach();
if(teker.attached()) teker.detach();
if(tekerkol.attached()) tekerkol.detach();
if(donduren.attached()) donduren.detach();
}
void attachedAll() {
if (!solkol.attached()) {
solkol.attach(lArm);
}
if (!sagkol.attached()) {
sagkol.attach(rArm);
}
if(!teker.attached()) {
teker.attach(wheel);
}
if(!tekerkol.attached()) {
tekerkol.attach(wArm);
}
if(!donduren.attached()) {
donduren.attach(turner);
}
}
void servoTurn(Servo v,int d, int angle) {
int sp = v.read();
int diff = angle -sp;
if(diff < 0) {
for(int i=0; i < abs(diff); i++) {
v.write(sp -i);
delay(d);
}
} else {
for(int i=0; i < diff; i++) {
v.write(sp +i);
delay(d);
}
}
}
28 Ekim 2018 Pazar
Book Page Turner Arduino Code
Kaydol:
Kayıtlar (Atom)