Beginners Serial input problem
i having trouble getting program wait key board input.
task use arduino uno output pwm waveform hardware , wait whilst make measurements. plan send serial byte (any byte) move on, increase pwm value predefined increment , repeat until max value of 255 reached.
the first wait loop wait1 working , can start program, wait until enter stepsize gets stuck in wait2 loop.
please can point me why code not work please.
tia
when enter stepsze2, serial window shows:
enter step size 1-9 step size =2
value 0
my code is
int val=0;
int stepsize=1;
int dummy=0;
void setup() {
serial.begin(9600); // opens serial port, sets data rate 9600 bps
serial.print ("enter step size 1-9 ");
wait1:
if (serial.available()==0) {
goto wait1;//wait key press
}
stepsize=serial.read()-48;//convert ascii number
serial.print("step size =");
serial.println(stepsize,dec);
serial.print ("value ");
serial.println(val,dec);
next:
{
analogwrite(9,val);
serial.flush();// might not needed?
wait2:
if (serial.available()==0) {
goto wait2; //wait key press <<<code gets stuck here
}
dummy=serial.read();// used read input buffer don't use data
val=val+stepsize;
if (val<=255) {
goto next;
}
}
}
void loop() {
}
this not basic. ditch stupid gotos , labels.
where assign value val? why expect contain other 0?
code: [select]
while(serial.available() == 0)
{
// nothing
}
where assign value val? why expect contain other 0?
Arduino Forum > Using Arduino > Programming Questions > Beginners Serial input problem
arduino
Comments
Post a Comment