Control Servo Motor With Joystick PS2
Today I will give you a tip how to control "Control Servo Motor with Joystick PS2". So what we need for this:
#include <servo.h> Servo Wheel; const int xPin = A0; const int yPIn = A1; const int swPin = 8; int xVal = 0; int yVal = 0; int zVal = 0; void setup(){ Wheel.attach(9); wheelDegree(90,250); pinMode(swPin, INPUT); digitalWrite(swPin, HIGH); Serial.begin(9600); } void loop(){ yVal = analogRead(yPin); if(yVal > 527){ wheelDegree(135,250); }else if(yVal <504){ wheelDegree(45,250); }else{ wheelDegree(90,250); } SerialMonitor(); } void wheelDegree(int degree, int ms){ Wheel.write(degree); delay(ms); } void SerialMonitor(){ Serial.print("X:"); Serial.print(analogRead(xPin),DEC); Serial.print("\tY:"); Serial.print(yVal,DEC); Serial.print("\tZ:"); Serial.print(digitalRead(swPin): delay(500): } | |
| |
Views: 1260 | | |
Total comments: 0 | |