Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Example By ArduinoAll
- #include <SoftwareSerial.h>
- int i = 0;
- int led = 13;
- char str[11] = {'0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'};
- SoftwareSerial mySerial(2, 3); // RX, TX
- void setup()
- {
- pinMode(led,13);
- Serial.begin(9600);
- mySerial.begin(9600);
- }
- void loop()
- {
- if (mySerial.available()) {
- i = i + 1;
- str[i] = mySerial.read();
- /*Serial.print(i);
- Serial.print(":");
- Serial.println(str[i]);*/
- if (i == 9){
- i = 0;
- }
- if(str[5]=='1'){ // สวิตช์ 1 กดเข้ามา
- if(str[7]=='3'){
- digitalWrite(led,1); // เปิดไฟ
- }else{
- digitalWrite(led,0);
- }
- }else if(str[5]=='2'){// สวิตช์ 2 กดเข้ามา
- if(str[7]=='3'){
- Serial.println("Switch 2 ON");
- }else{
- Serial.println("Switch 2 OFF");
- }
- }else if(str[5]=='3'){// สวิตช์ 3 กดเข้ามา
- if(str[7]=='3'){
- Serial.println("Switch 3 ON");
- }else{
- Serial.println("Switch 3 OFF");
- }
- }
- }
- if (Serial.available())
- mySerial.write(Serial.read());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement