I started with arduino last week and now Im trying a project where I have to use the serial port but this one when I try to read inputs from the computer doesnt read them well.
In this code if I dont write anything it prints the number -1 but if I write a number between 0-9 it prints 48-57 and then a 10 always. Someone can help me with that pls Im using an arduino UNO.
#include <LedControl.h>
LedControl lc = LedControl(11,10,9,0);
int r;
void setup() {
// put your setup code here, to run once:
lc.shutdown(0,true);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
r=Serial.read();
Serial.println(r);
delay(4000);
}
If you do that, you can not test for a character available by the usual method of checking for -1 because char is unsigned. You would have to use the available() method instead.