0% found this document useful (0 votes)
29 views

Code

The code declares variables to store a message and index. It sets up serial communication and an LED pin. The main loop continuously checks the serial input for 'ON' or 'OFF' and sets the LED high or low accordingly.

Uploaded by

ngocanh11595
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

Code

The code declares variables to store a message and index. It sets up serial communication and an LED pin. The main loop continuously checks the serial input for 'ON' or 'OFF' and sets the LED high or low accordingly.

Uploaded by

ngocanh11595
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

char msg[300];

int i;
char c;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(13, OUTPUT);
}

void loop() {
// put your main code here, to run repeatedly:
while(strstr(msg, "ON")) {
digitalWrite(13, HIGH);
delay(5000);
digitalWrite(13, LOW);
memset(&msg[0], 0, sizeof(msg));
i = 0;
}
while(strstr(msg, "OFF")) {
digitalWrite(13, LOW);
memset(&msg[0], 0, sizeof(msg));
i = 0;
}
while (Serial.available()) {
c = Serial.read();
if(i>200){
memset(&msg[0], 0, sizeof(msg));
i = 0;
}
else{
msg[i++]=c;
}
}
}

You might also like