الكود البرمجي :
int xVal; //X values from joystick
int yVal; //Y values from joystick
void setup() {
Serial.begin(9600); //Starts serial at 9600 baud
pinMode(A0, INPUT); //Sets the analog ports used to an input
pinMode(A1, INPUT);
}
void loop() {
xVal = analogRead(A0); //read the X value
yVal = analogRead(A1); //read the Y value
Serial.print(" Y = ");
Serial.print(yVal); //prints Y value
Serial.print(" X = ");
Serial.println(xVal); //prints X value
delay(1000); // so that we dont get a spam on the serial monitor
}
شرح الكود :
قمنا بتعريف متغيرين xVal، yVal إحداهما لتخزين قيمة X والأخر لتخزين قيمة Y ، حيث تمثل القيميتين موضع/موقع عصا التحكم.
في دالة التهيئة قمنا بتفعيل شاشة الاتصال التسلسلي، ثم ضبط الأطراف الموصله مع عصا التحكم كمدخل.
int xVal; //X values from joystick
int yVal; //Y values from joystick
void setup() {
Serial.begin(9600); //Starts serial at 9600 baud
pinMode(A0, INPUT); //Sets the analog ports used to an input
pinMode(A1, INPUT);
}
نقوم بقراءة قيم X و Y ثم عرض النتائج على شاشة الاتصال التسلسلي باستخدام الدالة (Serial.print(value .
void loop() {
xVal = analogRead(A0); //read the X value
yVal = analogRead(A1); //read the Y value
Serial.print(" Y = ");
Serial.print(yVal); //prints Y value
Serial.print(" X = ");
Serial.println(xVal); //prints X value
delay(1000); // so that we dont get a spam on the serial monitor
}

