Arduino and max

Hey guys :slight_smile:
I wanted to use a flex sensor as a trigger to a random list of sounds. I know i may have to use Max, bc my teacher taught us, but i don't know how. I have this code to connect the arduino uno to max

byte noteON = 144;//note on command
int analogPin = A0;

void setup() {
Serial.begin(9600);
}

void loop() {

int analogVal = analogRead(analogPin);//read data

//we have to scale the lsr data to fit between 0 and 127 (this is the range of MIDI notes)
byte note = map(analogVal, 0, 900, 0, 127);//falta mudar as variaveis

MIDImessage(noteON, note, 100);//turn note on
delay(300);//hold note for 300ms
MIDImessage(noteON, note, 0);//turn note off (note on with velocity 0)
delay(200);//wait 200ms until triggering next note
}

//send MIDI message
void MIDImessage(byte command, byte data1, byte data2) {
Serial.write(command);
Serial.write(data1);
Serial.write(data2);
}

  1. this is a school project for a grade so there can be limited help
  2. you should read the posting guidelines before posting and use code tags around your code

If the analog data you will get spans the 0 to 1023 ADC range then why use map() unless your major doesn't involve math?

Hello? 1024 / 8 = 128 as in 0 to 1023 divided by 8 gives 0 to 127

If you learn the Arduino BlinkWithoutDelay built-in example (in your IDE) then you can time events instead of using forced waits (the delays) and keep a tone playing only as long as the analog signal stays the same and change to match a new level within a millisecond or so of the change instead of having beeps tell you what it was.