From fd09e270eca5622066ec46507e540d761455340c Mon Sep 17 00:00:00 2001 From: adrian Date: Sun, 25 Jan 2026 21:10:34 +0100 Subject: [PATCH] servo rewrite --- roboterarm/roboterarm.ino | 62 +++++++++++++++++++++++++++++++++++++++ sketch_jan18a.ino | 49 ------------------------------- 2 files changed, 62 insertions(+), 49 deletions(-) create mode 100644 roboterarm/roboterarm.ino delete mode 100644 sketch_jan18a.ino diff --git a/roboterarm/roboterarm.ino b/roboterarm/roboterarm.ino new file mode 100644 index 0000000..0e3f808 --- /dev/null +++ b/roboterarm/roboterarm.ino @@ -0,0 +1,62 @@ +#include + +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); + } + + +} + + + + diff --git a/sketch_jan18a.ino b/sketch_jan18a.ino deleted file mode 100644 index 46ecd72..0000000 --- a/sketch_jan18a.ino +++ /dev/null @@ -1,49 +0,0 @@ -#include - -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); - } - - int Y_State = analogRead(Y_pin); - moveBase(Y_State); - -/* - Serial.print("Switch: "); - Serial.print(digitalRead(SW_pin)); - Serial.print("\n"); - Serial.print("X-axis: "); - Serial.print(analogRead(X_pin)); - Serial.print("\n"); - Serial.print("Y-axis: "); - Serial.println(analogRead(Y_pin)); - Serial.print("\n\n"); - delay(500); - */ - -} - -void moveBase(int pos) { - int newServoPos = pos * 0.1761; - ServoBase.write(newServoPos); - Serial.print(newServoPos); - Serial.print("\n"); - Serial.print(pos); - Serial.print("\n"); -} -