Created
March 7, 2019 15:59
-
-
Save myarduinosale/2f38547d33ad139cf4d6ead862202289 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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