I am going to send 8 or 10 chars from Arduino uno to MP3 player FN-M16P.
When i send only 4 chars every thing works fine, if i send 5 i get error codes from arduino.
call of overloaded 'write(int)' is ambiguous
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // RX, TX
const int byte8 = 7;
const int byte10 = 6;
char x = 0;
char y = 0;
//int start = 0x7H
void setup() {
pinMode(byte8, INPUT);
pinMode(byte10, INPUT);
// put your setup code here, to run once:
// set the data rate for the SoftwareSerial port
mySerial.begin(9600);
}
void loop() {
// spiller nr 10, når 7 sættes til vcc
x=digitalRead(byte8);
y=digitalRead(byte10);
if (x = 1){
mySerial.write (0x7E);
mySerial.write (0xFF);
mySerial.write (0x06);
mySerial.write (0x03);}
/* if (x = 1){
mySerial.write (0x00);
mySerial.write (0x00);
mySerial.write (0x0A);
mySerial.write (0xEF); }*/
// spiller nr 4, når 6 sættes til vcc
if (y = 1){
mySerial.write (0x7E);
mySerial.write (0xFF);
mySerial.write (0x06);
mySerial.write (0x03);}
/* if (y = 1){
mySerial.write (0x00);
mySerial.write (0x00);
mySerial.write (0x04);
mySerial.write (0xEF);
mySerial.write (0xEE);
mySerial.write (0xEF); }*/
}
When the compiler sees mySerial.write (0x00); it needs to decide which function to call.
in C++ when you don't specify the type of a integer literal, the default type is int if it fits the value, so 0x00 is not a byte, it's an int.
The compiler sees both options remains possible — an int could be promoted down to a byte or could represent an address in memory and thus it does not know which function to pick and you get a compilation message
call of overloaded 'write(int)' is ambiguous
by writing mySerial.write (byte(0x00)); you tell the compiler that 0x00 is actually of byte type - which is the same thing as uint8_t and so there is no more ambiguity, the compiler knows which function to call.
Ah, I see now.
Been having problems the last few weeks where the page does not automatically refresh and show the latest posts while I'm off working on my response.