servo rewrite
This commit is contained in:
62
roboterarm/roboterarm.ino
Normal file
62
roboterarm/roboterarm.ino
Normal file
@ -0,0 +1,62 @@
|
||||
#include <Servo.h>
|
||||
|
||||
Servo ServoBase;
|
||||
Servo ServoArmOne;
|
||||
const int SW_pin = 10;
|
||||
const int X_pin = A1;
|
||||
const int Y_pin = A0;
|
||||
|
||||
void setup () {
|
||||
ServoBase.attach(13);
|
||||
ServoArmOne.attach(12);
|
||||
Serial.begin(9600);
|
||||
pinMode(SW_pin, INPUT);
|
||||
digitalWrite(SW_pin, HIGH);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
bool SW = digitalRead(SW_pin);
|
||||
if (!SW) {
|
||||
ServoBase.write(90);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//base movement
|
||||
int Y_State = analogRead(Y_pin);
|
||||
int currentYState = ServoBase.read();
|
||||
|
||||
|
||||
if (Y_State > 524) {
|
||||
int newYState = currentYState + 1;
|
||||
ServoBase.write(newYState);
|
||||
delay(15);
|
||||
}else if (Y_State < 502) {
|
||||
int newYState = currentYState - 1;
|
||||
ServoBase.write(newYState);
|
||||
delay(15);
|
||||
}
|
||||
|
||||
//arm movement
|
||||
|
||||
int X_State = analogRead(X_pin);
|
||||
int currentXState = ServoArmOne.read();
|
||||
|
||||
|
||||
if (X_State > 524) {
|
||||
int newXState = currentXState + 1;
|
||||
ServoArmOne.write(newXState);
|
||||
delay(15);
|
||||
}else if (X_State < 502) {
|
||||
int newXState = currentXState - 1;
|
||||
ServoArmOne.write(newXState);
|
||||
delay(15);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user