Serial event error
in
Integration and Hardware
•
11 months ago
Hi.
I am having issues interfacing Arduino with Processing. I am learning and am still embarrassingly slow. The basic idea is to use analog force sensors to trigger wav files. I am able to trigger one file successfully but when I try to use two sensors to trigger two different wav files, errors occur: I am told:
unexpected token: void
basic thing like void stop() { or void draw() { are highlighted...
Guidance would be greatly appreciated..........
Arduino code:
- void setup() {
- Serial.begin(9600);
- }
- void loop() {
- // send the value of analog input 0:
- Serial.print(analogRead(A0), DEC);
- Serial.print(",");
- Serial.print(analogRead(A1), DEC);
- Serial.println("");
serial monitor registers values so this much works
Processing code:
- import processing.serial.*;
- import java.lang.Integer;
- import ddf.minim.*;
- Minim minim;
- AudioPlayer player;
- AudioSample one;
- AudioSample two;
- Serial myPort;
- String val;
- Serial myPort2;
- String val2;
- long lastDebounceTime = 0;
- long debounceDelay = 2000;
- //DO I NEED TWO DEBOUNCETIMES AND DELAYS IF I HAVE TWO SENSORS?
- void setup()
- {
- size(512, 200, P3D);
- minim = new Minim(this);
- one = minim.loadSample("one.wav");
- if ( one == null ) println("Didn't get one!");
- two = minim.loadSample("two.wav");
- if ( two == null ) println("Didn't get two!");
- myPort = new Serial(this, Serial.list()[0], 9600);
- myPort.bufferUntil('\n');
- myPort.clear();
- val = myPort.readStringUntil(10);
- val = null;
- myPort2 = new Serial(this, Serial.list()[1], 9600);
- myPort2.bufferUntil('\n');
- myPort2.clear();
- val2 = myPort2.readStringUntil(10);
- val2 = null;
- }
- void draw() {
- }
- void serialEvent (Serial myPort) {
- if (0 < myPort.available()) {
- val = myPort.readStringUntil(10);
- val = trim(val);
- if (0 < myPort2.available()) {
- val2 = myPort2.readStringUntil(10);
- val2 = trim(val2);
- }
- if ((millis() - lastDebounceTime) > debounceDelay) {
- if (int(val) > 200) {
- one.trigger();
- println("one trigger! & val = " + val);
- }
- if (int(val2) > 200) {
- two.trigger();
- println("two trigger! & val = " + val);
- }
- lastDebounceTime = millis();
- }
- }
- void stop()
- {
- one.close();
- two.close();
- player.close();
- minim.stop();
- super.stop();
- }
1