I'm at a loss. I've used Firmata to succesfully interface with processing and different sets of sensors, but I just can't get a stupid pushbutton to work. I'm doing something wrong either in syntax or serial communication, but it's still weird.
I wanted three pushbuttons to toggle different sensors, but no digital input button seems to work in Proc/Firmata. When I load up the buttonsketch in Arduino itself (http://www.arduino.cc/en/Tutorial/Button) It works a charm, so my breadboardschematic and arduino are working fine. However, when I set the exact same thing up in processing with Firmata loaded, I notice that LED pin 13 can't even be toggled on and off and it seems that the loop is doing weird things (making the RX led blink erratic instead of 13, as if the if loop isn't checking properly).
this is my code:
import processing.serial.*;
import cc.arduino.*;
Arduino arduino;
PImage backgroundIMG;
// Images must be in the "data" directory to load correctly
// Kleur blauw (R G B)
color blauw = color(0,0,180);
color groen = color(0,180,0);
color zwart = color(0,0,0);
color grijs = color(200,200,200);
/////////////////////////////////////////////////////////////////
//////////////////SETUP//////////////////////////////////////////
/////////////////////////////////////////////////////////////////
void setup() {
// Grootte van je window
size(800, 600);
background(255);
// Geen stroke
noStroke();
backgroundIMG = loadImage("oogkas.jpg");
// initialiseer Arduino
arduino = new Arduino(this, Arduino.list()[0], 57600);
// Gebruik pin 0 als INPUT
arduino.pinMode(0, Arduino.INPUT);
arduino.pinMode(1, Arduino.INPUT);
arduino.pinMode(7, Arduino.INPUT);
arduino.pinMode(13, Arduino.OUTPUT);
arduino.pinMode(3, Arduino.INPUT);
arduino.pinMode(12, Arduino.INPUT);
arduino.pinMode(11, Arduino.INPUT);
arduino.pinMode(10, Arduino.INPUT);
// imgSleep = loadImage("low.jpg");
// imgWake = loadImage("high.jpg");
}
////////////////*********************////////////////////////////
////////// DRAW //////////////////////////////////////
////////////////*********************////////////////////////////
void draw() {
background(backgroundIMG);
if (arduino.digitalRead(7) == Arduino.HIGH) {
print("BUTTON PRESSED");
arduino.digitalWrite(13, Arduino.HIGH);
} else {
arduino.digitalWrite(13, Arduino.LOW);
}
// toggleSensors();
// sonicDist();
// lightSensor();
// infraDist();
// delay(20);
}
I've triend nearly all digital inputs, but no pushbutton seems to give the correct result.Also, if i change 'if (arduino.digitalRead(7) == Arduino.HIGH) ' to Arduino.LOW, it will say 'button pressed', but i can't seem to change from HIGH to LOW...