call of overloaded write(int) is ambiguous
arduino, c++, robotics
Solution
`0x00` can be interpreted as both an integer literal or a pointer literal. The compiler doesn't know which you mean, as you have overloads for both.
So change that line to:
Roomba.write((byte)0x00);
or the slightly more verbose C++-style cast:
Roomba.write(static_cast<byte>(0x00));
Problem
The code below works fine WITHOUT the function spinLeft() (which I copied from goForward and modified). When I tried to add that function (to be used later) I got the error above. But I can't see where I did anything not already done. How did adding another function generate this error? The rest of the error message says: ``` Roomba4operants.ino: In function 'void spinLeft()': Roomba4operants:57: error: call of overloaded 'write(int)' is ambiguous /Users/royclymer/Desktop/Arduino.app/Contents/Resources/Java/libraries/SoftwareSerial/SoftwareSerial.h:92: note: candidates are: virtual size_t SoftwareSerial::write(uint8_t) /Users/royclymer/Desktop/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/Print.h:49: note: size_t Print::write(const char*) ``` Code: ``` #include <SoftwareSerial.h> int rxPin = 3; int txPin = 6; int ledPin = 13; SoftwareSerial Roomba(rxPin,txPin); void setup() { pinMode(ledPin, OUTPUT); // sets the pins as output Serial.begin(115200); Roomba.begin(115200); digitalWrite(ledPin, HIGH); // say we're alive Serial.println ("Sending start command..."); delay (1000); // set up ROI to receive commands Roomba.write(128); // START delay(150); Serial.println ("Sending Safe Mode command..."); delay (1000); Roomba.write(131); // SAFE delay(150); digitalWrite(ledPin, LOW); // say we've finished setup Serial.println ("Ready to go!"); delay (5000); } void loop() { digitalWrite(ledPin, HIGH); // say we're starting loop Serial.println ("Go Forward"); goForward(); delay (1000); Serial.println ("Halt!"); halt(); Serial.println ("Go Backwards"); delay (200); goBackward(); delay (1000); Serial.println ("Halt!"); halt(); while(1) { } // Stop program } void goForward() { Roomba.write(137); // DRIVE Roomba.write((byte)0x00); // 0x00c8 == 200 Roomba.write(0xc8); Roomba.write(0x80); Roomba.write((byte)0x00); } void spinLeft() { Roomba.write(137); // DRIVE Roomba.write((byte)0x00); // 0x00c8 == 200 Roomba.write(0xc8); Roomba.write(0x00); //0x0001==spin left Roomba.write((byte)0x01); } void goBackward() { Roomba.write(137); // DRIVE Roomba.write(0xff); // 0xff38 == -200 Roomba.write(0x38); Roomba.write(0x80); Roomba.write((byte)0x00); } void halt(){ byte j = 0x00; Roomba.write(137); Roomba.write(j); Roomba.write(j); Roomba.write(j); Roomba.write(j); } ```