Hi all! I have a switch attached to one arduino, and I am trying to convey the state of the switch to another arduino via serial connection.
On the TX board I have the following code:
int LightsOn = 0;
int LightsPin = 17;
void setup(void) {
Serial.begin(9600);
Serial2.begin(9600);
pinMode(LightsPin, INPUT_PULLDOWN);
void loop(void) {
if (digitalRead(LightsPin) == LOW)LightsOn = 1;
if (digitalRead(LightsPin) == HIGH)LightsOn = 0;
Serial2.println(LightsOn);
//Serial.println(LightsOn);
}
On the RX board I have this code:
//----- Backlighting
int DashLEDPin = 35;
int PointerLEDPin = 36;
int FrontLEDPin = 37;
int RearLEDPin = 38;
int PointerBrightness = 255;
int FrontBrightness = 25;
int RearBrightness = 25;
int DashBrightness = 255;
//---Outputs
int Output_Lights1 = 14;
int Output_AC_LED = 1;
int rc = 0;
void setup() {
pinMode(Input_Sidelights, INPUT_PULLUP);
pinMode(Input_AC, INPUT_PULLDOWN);
pinMode(Output_Lights1, OUTPUT);
pinMode(Output_AC_LED, OUTPUT);
Serial5.begin(9600);
}
void loop() {
Get_Serial_Data();
}
//-----------------------Receive Serial Data--------------------------------------------------------
void Get_Serial_Data() {
//inChar = Serial1.read();
if (Serial5.available() > 0) {
rc = Serial5.read();
Serial.println();
if (rc == 1) {
analogWrite(PointerLEDPin, PointerBrightness);
analogWrite(FrontLEDPin, FrontBrightness);
analogWrite(RearLEDPin, RearBrightness);
}
else {
}
}
}
For some reason, on the RX board, I see a few random integers on the serial5 read (10, 48 etc) and the 48 changes to 49 when I flick the switch. I'm not sure what's going on here, why isn't it just reading 0 or 1?
Thanks,
Nick