Hi. Can someone help me with debugging the codes below? It is for toggling between 2 LEDs using Bluetooth operated by a phone app I designed using MIT app inventor. Below consist of 2 separate codes for energia . I use 2 tabs in energia to run both codes simultaneously to make LED1 light up when my click LED1 on my phone app and vice versa for LED2. Thanks in advance. CODE 1: void setup() { pinMode(39,OUTPUT); Serial.begin(9600); Serial1.begin(9600); } void loop() { while(Serial1.available()>0) { char message =Serial1.read(); if(message=='on2') { digitalWrite(39,HIGH); } else if (message=='off2') { digitalWrite(39,LOW); } else { analogWrite(39,int(message)); } } } CODE 2: void setup() { pinMode(40,OUTPUT); Serial.begin(9600); Serial1.begin(9600); } void loop() { while(Serial1.available()>0) { char message =Serial1.read(); if(message=='on1') { digitalWrite(40,HIGH); } else if (message=='off1') { digitalWrite(40,LOW); } else { analogWrite(40,int(message)); } } }
↧