Hi all Arduinoers!
I am at my wits end with trying to solve a very basic Arduino2Max problem. I have a force sensitive resistor connected, via a breadboard, to an Arduino BT w/AT Mega 328. I had spent a lot of time just getting the program loaded onto the Arduino, but seem to have finally managed that now. Below is the programming code that I am using for this. All I would like to do is read data from Analog port 0, and have this displayed on the standard max patch.
Can anybody see where I am going wrong? I will included a picture of the breadboard set up (when I can figure out how), as I have tried a couple of arrangements taken from different sources and am unsure if it is correct. I am using a 10k ohm resistor. I also changed the last line of the programming code to Serial.write(32); as it Arduino could not understand 'BYTE', although I am not sure what the best value to put in here would be. The max patch has the serial reader linked to ARDUINOBT-Bluetoothseri and the correct port has been selected
Again, any help would be massively appreciated - I now have a splitting headache and need to suss this so that I can continue with my project. Sorry to trouble you with such a basic issue but I cant help feel that it's something really small that I keep overlooking.
Thanks in advance
AT
(Basic Arduino to Max Code)
/*
- Arduino2Max
- Send pin values from Arduino to MAX/MSP
- Arduino2Max.pde
-
- This version: .5, November 29, 2010
-
- Copyleft: use as you like
- by Daniel Jolliffe
- Based on a sketch and patch by Thomas Ouellet Fredericks tof.danslchamp.org
*/
int x = 0; // a place to hold pin values
int ledpin = 13;
void setup()
{
Serial.begin(115200); // 115200 is the default Arduino Bluetooth speed
digitalWrite(13,HIGH); ///startup blink
delay(600);
digitalWrite(13,LOW);
pinMode(13,INPUT);
}
void loop()
{
if (Serial.available() > 0){ // Check serial buffer for characters
if (Serial.read() == 'r') { // If an 'r' is received then read the pins
for (int pin= 0; pin<=5; pin++){ // Read and send analog pins 0-5
x = analogRead(pin);
sendValue (x);
}
for (int pin= 2; pin<=13; pin++){ // Read and send digital pins 2-13
x = digitalRead(pin);
sendValue (x);
}
Serial.println(); // Send a carriage returnt to mark end of pin data.
delay (5); // add a delay to prevent crashing/overloading of the serial port
}
}
}
void sendValue (int x){ // function to send the pin value followed by a "space".
Serial.print(x);
Serial.write(32);
}