ลองเลือกอุปกรณ์ก่อน ที่ออกแบบไว้เป็นตัวไหนบ้าง ผมจะได้ช่วยแนะนำเพิ่มได้ครับ
ถ้าอธิบายให้ทำได้ ต้องใช้เวลาหลายวัน เป็นคอร์สเลยครับ ดังนั้นขอสรุปแนวทางศึกษาเพิ่มเติมดังนี้
ศึกษาข้อมูลตามนี้ให้เข้าใจเพื่อเขียนโปรแกรมที่เป็นของตัวเองตามต้องการครับ
#define R 13 //กำหนดขาที่นำไปต่อกับรีเลย์
#define L 12
int ledPin = 13;
int joyPin1 = 0; // slider variable connecetd to analog pin 0
int joyPin2 = 1; // slider variable connecetd to analog pin 1
int value1 = 0; // variable to read the value from the analog pin 0
int value2 = 0; // variable to read the value from the analog pin 1
void setup()
{
// Open serial communications and wait for port to open:
pinMode(ledPin, OUTPUT); // initializes digital pins 0 to 7 as outputs
pinMode(R, OUTPUT); // กำหนดโหมดให้เป็น Output
pinMode(L, OUTPUT);
Serial.begin(9600);
}
int treatValue(int data) {
return (data * 9 / 1024) + 48;
}
void loop() // run over and over
{
// reads the value of the variable resistor
value1 = analogRead(joyPin1);
// this small pause is needed between reading
// analog pins, otherwise we get the same value twice
// reads the value of the variable resistor
value2 = analogRead(joyPin2);
digitalWrite(ledPin, LOW);
digitalWrite(R, HIGH);
digitalWrite(L, LOW);
delay(value1);
digitalWrite(L, HIGH);
digitalWrite(R, LOW);
digitalWrite(ledPin, LOW);
delay(value2);
Serial.print('J');
Serial.print(treatValue(value1));
Serial.println(treatValue(value2));
}
ผมใส่คำสั่งนี้ลงไป ไม่ทราบว่าจะทำยังไงให้มันหยุดทำงานก่อนที่เราจะกดจอยให้มันเคลื่อนที่ครับ
มันบังคับหมุนซ้ายขวาได้แล้วแต่เสียบไปมันทำงานเรย จะให้มันหยุดก่อนใช้คำสั่งไหนครับ