Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

this code is for joystick control. plx fix this same code for me. //Add LCD Library #include LiquidCrystal lcd(1, 2, 4, 5, 6, 7); //Adding

this code is for joystick control. plx fix this same code for me.

//Add LCD Library #include LiquidCrystal lcd(1, 2, 4, 5, 6, 7);

//Adding the Servo Library #include

//This sketch will be using Two Servo Motors Servo myservo; Servo myservo2;

//Joystick Pins x and Y Connected to Analog Pins int Joystickx = 0; int Joysticky = 1; int Joysticki = 0; int Joystickj = 0;

//Variables that will read Analog Pin Values int Joystickval; int Joystickval2; int analogPin= A1; int analogPin2= A0;

//Variables will be used to hold the value or position of the Servo Positions int Joystickposx=0; int Joystickposxcurrent_pos=0; int Joystickposy=0; int Joystickposycurrent_pos=0;

//Servo Motors need PWM, so attach servo on PWM 3 and 8 void setup() { lcd.begin(16,2); myservo.attach(9); myservo2.attach(3); } //Loop is used to control the movements of First Servo Motor Joystickval=analogRead(analogPin); Joystickposx=map(Joystickval, 0,1023, 0, 180); if(Joystickposx!= Joystickposxcurrent_pos); myservo.write(Joystickposx); Serial.println(" Servo1 Angle in degrees= "); Serial.print(Joystickposx); Serial.print("/t Read Value (from an analog input)= "); Serial.println(Joystickval); delay(100);

//Lines are included to print the Angle of Servo 1 on the LCD Monitor lcd.setCursor(0,0); lcd.print("Tilt:"); Joystickposx=Joysticki; lcd.print(Joysticki); lcd.print((char)223); //This line is included to read the analog value of the First Servo Motor lcd.setCursor(9,0); lcd.print("A1="); lcd.print(Joystickval); //Loop is used to control the movements of Second Servo Motor Joystickval2=analogRead(analogPin2); Joystickposy=map(Joystickval2, 0,1023, 0, 180); myservo2.write(Joystickposy); Serial.println(" Servo2 Angle in degrees= "); Serial.print(Joystickposy); Serial.print("/t Read Value (from an analog input)= "); Serial.println(Joystickval2); delay(100); //Lines are included to print the Angle of Servo 2 on the LCD Monitor lcd.setCursor(0,1); lcd.print("Tilt 2:"); Joystickposy=Joystickj; lcd.print(Joystickj); lcd.print((char)223);

//This line will read the analog value of The Second Servo Motor lcd.setCursor(9,16); lcd.print("A2="); lcd.print(Joystickval2);

// Blinks the LEDs when the Joystick is moved Horizontally/Vertically according to its designed axis Joysticki = analogRead(Joystickx); Joystickj = analogRead(Joysticky); Joysticki = map(Joysticki, 0, 1023, 0, 180); Joystickj = map(Joystickj, 0, 1023, 0, 255); analogWrite(12, Joystickj); analogWrite(11, Joysticki); }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

2. KMPG LLP

Answered: 1 week ago

Question

5. Wyeth Pharmaceuticals

Answered: 1 week ago