Optimization Problem
hello, newbie when comes arduino platform. as being such, have started play around of basics. one thing cannot seem past seems variables getting optimized out. for example see code below. the program works fine when serial.println on-commented fails them commented out. i trying make state machine using inputs serial port should go , do. i thought using switch case since 1 byte can read in serial port, thought may better choice. sure there way around this, or maybe using bad coding practices. any great.
#define _bell 13
int head = 0;
int data = 0;
void setup(){
serial.begin(9600);
pinmode(_bell ,output);
}
void loop(){
if (serial.available() > 0){
head = serial.read();
//serial.println((char)head);
if(head == 't'){
data = serial.read();
//serial.println((char)data);
if (data == 'h'){
digitalwrite(_bell,high);
}
if (data == 'l'){
digitalwrite(_bell,low);
}
}
}
}
#define _bell 13
int head = 0;
int data = 0;
void setup(){
serial.begin(9600);
pinmode(_bell ,output);
}
void loop(){
if (serial.available() > 0){
head = serial.read();
//serial.println((char)head);
if(head == 't'){
data = serial.read();
//serial.println((char)data);
if (data == 'h'){
digitalwrite(_bell,high);
}
if (data == 'l'){
digitalwrite(_bell,low);
}
}
}
}
try insert short delay, if fixes option change (serial.available() > 0) (serial.available() == 2)
Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > Optimization Problem
arduino
Comments
Post a Comment