int potPin = 4;
int ledPin = 2;
void setup() {
Serial.begin(115200);
Serial2.begin(9600, SERIAL_8N1, 16, 17);
pinMode(potPin, INPUT);
pinMode(ledPin, OUTPUT);
}
void loop() {
int Value = analogRead(potPin);
int Mapped = map(Value, 0, 4095, 0, 255);
Serial2.write(Mapped);
if (Serial2.available()) {
int recValue = Serial2.read();
analogWrite(ledPin, recValue);
}
}