Skip to content

Instantly share code, notes, and snippets.

@myarduinosale
Created March 7, 2019 15:59
Show Gist options
  • Save myarduinosale/2f38547d33ad139cf4d6ead862202289 to your computer and use it in GitHub Desktop.
Save myarduinosale/2f38547d33ad139cf4d6ead862202289 to your computer and use it in GitHub Desktop.
char key = '0' ; //ตัวแปรเก็บค่าที่คอมพิวเตอร์ส่งมา
void setup()
{
Serial.begin(9600);
Serial.println("My arduino");
}
void loop()
{
if (Serial.available() > 0) { //ถ้าคอมพิวเตอร์ส่งข้อมูลมาใหจะทำใน if นี้
key = Serial.read(); //นำค่าที่คอมพิวเตอร์ส่งมาเก็บในตัวแปร key
Serial.print("key : ");
Serial.println(key); //Arduino ส่งค่าในตัวแปร key เข้าคอมพิวเตอร์ Serial Monitor
}
if (key == '1') { //ถ้าตัวแปร key เท่ากับ 1 ให้ทำในปีกกานี้
Serial.println("myarduino 1"); // Arduino ส่งข้อความตอบกลับมาทาง Serial Monitor "myarduino 1"
}
else { //ถ้า key ไม่เท่ากับ 1 ให้ทำในปีกกานี้
Serial.println("I Love Myarduino");
}
delay(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment