Arduino to Processing, Serial missbehaviour
in
Integration and Hardware
•
1 year ago
Dear forum
I'm trying to integrate the Arduino into my Processing sketches and it's kind of working , but not properly.
The idea is that when I press a button down, the Arduino sends a buttonspecific number, which is in this case 10 or 20, and then sends a 1 or a zero depending on the state of the button.
Now if I press one button, it prints out that both buttons have been pressed:
The Arduino Code:101201
- int button1 = 4;
- int button2 = 5;
- int einser = 10;
- int An = 1;
- int Ab = 0;
- int zweier = 20;
- boolean eins = false;
- boolean zwei = false;
- void setup()
- {
- Serial.begin(9600);
- pinMode(button1, INPUT);
- pinMode(button2, INPUT);
- }
- void loop()
- {
- if(digitalRead(button1) == HIGH && eins == false)
- {
- eins = true;
- Serial.write(einser);
- Serial.write(An);
- //Serial.println("1");
- }
- else if(digitalRead(button1) == LOW && eins == true)
- {
- eins = false;
- Serial.write(einser);
- Serial.write(Ab);
- }
- if(digitalRead(button2) == HIGH && zwei == false)
- {
- zwei = true;
- Serial.write(zweier);
- Serial.write(An);
- //Serial.println("2");
- }
- else if(digitalRead(button2) == LOW && zwei == true)
- {
- zwei = false;
- Serial.write(zweier);
- Serial.write(Ab);
- }
- }
- import processing.serial.*;
- int[] dataIn = new int[2];
- Serial port;
- int counter;
- void setup()
- {
- port = new Serial(this, Serial.list()[1], 9600);
- }
- void draw()
- {
- if(port.available() > 0)
- {
- dataIn[counter] = port.read();
- println(dataIn[counter]);
- counter = (counter+1) % 1;
- }
- }
cheers
bluebubble
1