I would like to know how to read the serialin data, so I can make the led's ramp up from 0 to 253.
The data I am reading on the rx side of the serial Monitor is this
(Sensor 1 = 255202255 Sensor 2 = 2550254 Sensor 1 = 255202255 Sensor 2 = 2550254)
As I ramp up the pot, the data moves from 0 to 202 on the Sensor = 1.
Here is the programs I am working with.
TX
int analogValue2, analogValue5, val2, val5;
void setup()
{
// start serial port at 19200 bps
Serial.begin(19200);
}
void loop()
{
// read analog input
analogValue2 = analogRead(0);
analogValue5 = analogRead(4);
// remap values
val2 = map(analogValue2, 0, 1023, 0, 253); // 254 and 255 for SYNC
val5 = map(analogValue5, 0, 1023, 0, 253);
Serial.write(254); //SYNC char
Serial.write(val2);
Serial.write(255); //SYNC char
Serial.write(val5);
delay(150);
}
RX
byte incomingByte, sensor1, sensor2;
void setup() {
// start serial port at 19200 bps
Serial.begin(19200);
Serial.println("Ready!");
// led pins
pinMode (10, OUTPUT);
pinMode (11, OUTPUT);
delay(1000);
}
void loop() {
if (Serial.available()) { // are there any bytes available on the serial port ???
// assign bytes to the var ‘incomingByte’
incomingByte = Serial.read();
Serial.print(int(incomingByte));
// from now on is pretty clear I guess :)
if ((int(incomingByte) == 254)) {
sensor1 = Serial.read();
Serial.print(" Sensor 1 = ");
Serial.print(int(sensor1));
}
if ((int(incomingByte) == 255)) {
sensor2 = Serial.read();
Serial.print(" Sensor 2 = ");
Serial.print(int(sensor2));
}
}
analogWrite (10, sensor1);
analogWrite (11, sensor2);
}