Serial.write not posting correct data

Hey all, I'm trying to send data from a flex sensor into Max 7 via serial(9600).

The serial monitor is posting correct data in Arduino, but I'm getting random

single channel data in Max 7 that isn't even close to the (flexposition) data.

I don't know why the data would be different.

Code is below, thank you for your help.


const int flexpin = 0;

void setup()
{

Serial.begin(9600);

}

void loop()
{
int flexposition; // Input value from the analog pin.

flexposition = analogRead(0);

Serial.println(flexposition);
Serial.write(flexposition);

delay(20); // wait 20ms between servo updates
}

Serial.write(val) writes a single byte you trying to wire something like 1024.

Good article here

https://www.gammon.com.au/serial

You need to decide if you are going to use print() (or println()) to send ASCII data to the serial port OR use write() to send the data.

If you are going to use write(), you need to, as KrisKasprzak says, deal with the fact that write() takes a byte, and you have an int.