Reputation: 2607
I am having a small problem with an Arduino program I am trying to write to read a command sent from Processing over a serial connection. Processing is supposed to send either a 'H' or an 'L' over the serial connection to the Arduino. This value is stored as a char in my program but when I try to do Serial.write("Value: %c",val) I get a "Invalid Conversion from 'const char*' to 'const uint8_t*'" error. If someone can help me solve this problem that would be great. I really need to figure out what this value is so I can re-write my program. Thanks!
Code is provided below:
char val; // variable to receive data from the serial port
int ledpin = 8; // LED connected to pin 48 (on-board LED)
void setup() {
pinMode(ledpin, OUTPUT); // pin 48 (on-board LED) as OUTPUT
Serial.begin(9600); // start serial communication at 9600bps
}
void loop() {
while (Serial.available()>0){
val=Serial.read();
}
//Serial.write("Value: %c",(char)val);
if( val == 'H' ) // if 'H' was received
{
Serial.write("Setting Value to High \n");
digitalWrite(ledpin, HIGH); // turn ON the LED
} else {
Serial.write("Setting Value to Low \n");
digitalWrite(ledpin, LOW); // otherwise turn it OFF
}
Serial.flush();
delay(100); // wait 100ms for next reading
}
Upvotes: 2
Views: 5027
Reputation: 1904
use in stead of serial.write: Serial.print or Serial.println(witch prints at the end of the string \r\n)
Upvotes: 0
Reputation: 97641
Serial.write
is not printf
- it doesn't take a format string as an argument. Have a look at the documentation.
Upvotes: 3