I need to send data from one arduino to an other. To do so I need to convert the int to an array of chars (specifically to ASCII caracters), send them and "decode" them back to the int. I will use a value of a PWM, map it between 0 and 255 so theoretically I need an array of 3 chars. Thats all that I know so far.
#define PWM_PIN A0
int PWM_Value = 0;
char Brightness = 0;
void setup() {
Serial.begin(9600);
pinMode(PWM_PIN, INPUT);
}
void loop() {
PWM_Value = analogRead(PWM_PIN);
Brightness = map(PWM_Value, 0, 1023, 0, 255);
Serial.println(Brightness);
int BrightnessArray[3]; // Because I'll use only 3 digits
delay(1000);
}
I have 0 experience with arrays and don't know how to proceed with them
Skiermaxhtc:
And I can receive them on the other arduino by the same method? I mean by Serial.read().
What if I'll have more potentiometers?
as it fits on 1 byte, if this is the only thing you send, don't bother going ASCII. just send the byte with Serial.write() and read it on the other side with a Serial.read() and you'll have your value
You are correct J-M-L. That should have been a 4 character array for the null. I haven’t used any of those functions on the Arduino so I haven’t surveyed the memory footprint.
The best solution would be to frame the data so the receiver knows it is in sync with the transmitter. But that is another subject.
ToddL1962:
You are correct J-M-L. That should have been a 4 character array for the null. I haven’t used any of those functions on the Arduino so I haven’t surveyed the memory footprint.
The best solution would be to frame the data so the receiver knows it is in sync with the transmitter. But that is another subject.
I think on any platform snprintf() will add the trailing null char
Indeed, framing the data is usually the way to go - here if it is only 1 byte that has to be sent (and if there is no need for verifying it’s sent without error) then just pushing that byte would make development easy