I am having troubles with my arduino micro.
In my programming, I am using the serial. When I use println, nothing shows up in the serial monitor except for 0
. So if I type 1
, I get back 0
instead of 1
, same goes for 3241234
or any random number.
Here is the code:
void setup() {
Serial.begin(9600); //Connect to the serial monitor console
}
void loop() {
while (Serial.available() == 0); //Wait until Serial is available
//Read val
int val = Serial.read() - '0'; //Val that represents input
delay(500);
Serial.println(val);
}
So I have another problem and people have asked for the code. Basically, printing a string returns 0.
void setup() {
Serial.begin(9600); //Connect to the serial monitor console
}
void loop() {
while (Serial.available() == 0); //Wait until Serial is available
//Read val
int val = Serial.read(); //Val that represents input
delay(1000);
if (val == 1) {
Serial.print('Firing the motor');
} else {
Serial.print('Please press 1 to fire the motor.');
}
delay(4000);
}
Instead of printing Please press 1 to fire the motor, I get 0 in the console.
Thanks for the help!