Skip to content
Permalink
Browse files
Moved servo with joystick
  • Loading branch information
sarkarj committed Feb 8, 2020
1 parent b3d0662 commit 69433e0a21725015743c5020097c9b43e846698c
Showing 1 changed file with 43 additions and 0 deletions.
@@ -0,0 +1,43 @@

#include <Servo.h>
Servo servo;

const int sw = 2;
const int x = 0;
const int y = 1;
int xjoypos;
int i = 0;

void setup() {
pinMode(sw, INPUT);
digitalWrite(sw, HIGH);
Serial.begin(115200);
servo.attach(3);
servo.write(0);


}

void loop() {
Serial.print("Switch: ");
Serial.print(digitalRead(sw));
Serial.print("\n");
Serial.print("X - axis: ");
Serial.print(analogRead(x));
Serial.print("\n");
Serial.print("Y - axis: ");
Serial.print(analogRead(y));
Serial.print("\n\n");
xjoypos = analogRead(x);
if (xjoypos > 520)
{
if(i < 180)i+=10;
}
if (xjoypos < 500)
{
if(i > 0) i -= 10;
}
servo.write(i);
delay(15);

}

0 comments on commit 69433e0

Please sign in to comment.