Hi everyone,
I have a hard time making Arduino communicating with processing:
My circuit is pretty simple: i have 12 buttons related to my arduino uno and i want that each of them make processing do a single task. For example, when buttonpin4 is pressed, processing would launch "beat it.mp3".
Starting with my arduino code below, what should i write in the processing code to make it understand the arduino strings?
Thanks in advance
// constants won't change. They're used here to set pin numbers:
const int buttonPin0 = 15;
const int buttonPin1 = 14;
const int buttonPin2 = 2;
const int buttonPin3 = 3;
const int buttonPin4 = 4;
const int buttonPin5 = 5;
const int buttonPin6 = 6;
const int buttonPin7 = 7;
const int buttonPin8 = 8;
const int buttonPin9 = 9;
const int buttonPin10 = 10;
const int buttonPin11 = 11;
const int buttonPin12 = 12;
const int buttonPin13 = 13;
const byte buttonPin[] = {15, 14, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}; //array: remplace ce qui est au dessus
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
int incomingByte;
void setup() {
Serial.begin(9600);
pinMode(buttonPin1, INPUT);
pinMode(buttonPin2, INPUT);
pinMode(buttonPin3, INPUT);
pinMode(buttonPin4, INPUT);
pinMode(buttonPin5, INPUT);
pinMode(buttonPin6, INPUT);
pinMode(buttonPin7, INPUT);
pinMode(buttonPin8, INPUT);
pinMode(buttonPin9, INPUT);
pinMode(buttonPin10, INPUT);
pinMode(buttonPin11, INPUT);
pinMode(buttonPin12, INPUT);
pinMode(buttonPin13, INPUT);
pinMode (buttonPin[15, 14, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13], INPUT);
}
void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin1);
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
Serial.write('A'); //quelque chose a la place de "ledpin"
} else {
// turn LED off:
Serial.write('L');
}
buttonState = digitalRead(buttonPin2);
if (buttonState == HIGH) {
Serial.write('B');
} else {
Serial.write('L');
}
buttonState = digitalRead(buttonPin3);
if (buttonState == HIGH) {
Serial.write('C');
} else {
Serial.write('L');
}
buttonState = digitalRead(buttonPin4);
if (buttonState == HIGH) {
Serial.write('D');
} else {
Serial.write('L');
}
buttonState = digitalRead(buttonPin5);
if (buttonState == HIGH) {
Serial.write('E');
} else {
Serial.write('L');
}
buttonState = digitalRead(buttonPin6);
if (buttonState == HIGH) {
Serial.write('F');
} else {
Serial.write('L');
}
buttonState = digitalRead(buttonPin7);
if (buttonState == HIGH) {
Serial.write('G');
} else {
Serial.write('L');
}
buttonState = digitalRead(buttonPin8);
if (buttonState == HIGH) {
Serial.write('H');
} else {
Serial.write('L');
}
buttonState = digitalRead(buttonPin9);
if (buttonState == HIGH) {
Serial.write('I');
} else {
Serial.write('L');
}
buttonState = digitalRead(buttonPin10);
if (buttonState == HIGH) {
Serial.write('J');
} else {
// turn LED off:
Serial.write('L');
}
buttonState = digitalRead(buttonPin11);
if (buttonState == HIGH) {
Serial.write('K');
} else {
Serial.write('L');
}
buttonState = digitalRead(buttonPin12);
if (buttonState == HIGH) {
Serial.write('M');
} else {
Serial.write('L');
}
buttonState = digitalRead(buttonPin13);
if (buttonState == HIGH) {
Serial.write('N');
} else {
Serial.write('L');
}
}