I'm trying to make an I2C communication between a master Arduino Nano and a slave Arduino Uno. In the master part, I want the serial of the Arduino Nano to read my input.. if I write "red" as an input, I want the master Arduino Nano to write "red" to the slave so that the Arduino Uno can detect "red" and turn on the red LED. But they're giving me an error that I don't understand on Wire.write(color); the error message is so long, but I will paste a part of it:
error: no matching function for call to 'TwoWire::write(String&)'
Wire.write(color);
note: candidate: virtual size_t TwoWire::write(uint8_t)
virtual size_t write(uint8_t);
..
Arduino Nano Master code (where the error is located):
// MASTER NANO
#include <Wire.h>
#define slave_adr 0x11
String color = "";
void setup() {
Wire.begin();
Serial.begin(9600);
}
void loop() {
while (Serial.available()==0) {}
color = Serial.readString();
delay(100);
Wire.beginTransmission(slave_adr);
Wire.write(color);
Wire.endTransmission();
delay(500);
}
Arduino Uno slave code (until now, no errors):
// SLAVE UNO
#include <Wire.h>
#define slave_adr 0x11
String led = "";
int red = 10;
int green = 9;
int blue = 8;
void setup() {
Wire.begin(slave_adr);
Wire.onReceive(receiveEvent);
pinMode(red, OUTPUT);
pinMode(green, OUTPUT);
pinMode(blue, OUTPUT);
}
void loop() {
}
void receiveEvent() {
while (Wire.available() > 1) {
char c = Wire.read();
led += c;
}
if (led == "red") {
digitalWrite(red, HIGH);
} else {
digitalWrite(red, LOW);
}
}