Hello,
been away from civilisation for a while, now back to project
I am using the Standard Firmrata, uploaded into arduino, and it's library in the Processing, to control the arduino.
The code in the processing is very simple:
there is a button, which when pressed, executes the function.
But that function works only once. closing and reopening application does not help. only if i retart the computer, it works only once again for one time
the code in the processing is:
// screen background color
int backgroundColor = color(150); //background colour
// load the font
PFont font; //declare the font variable
// button operation variables
boolean BDC = false;
boolean loadCell = false;
int bdcColor = color(227, 23, 23);
int loadCellColor = color(200);
int startColor = color(200);
// setup Arduino communication
import processing.serial.*;
import cc.arduino.*;
Arduino arduino;
int hallPin = 9; // hall sensor pin (digital read)
int onPin = 7; // on / off switch pin (digital write)
void setup() {
// screen setup
size(1000, 680); // screen size
smooth(); // smooth lines
noStroke(); // no lines
background(backgroundColor);
fill(245);
//rect(15, 115, 970, 600);
stroke(200); // chart grey lines
line(23, 190, 977, 190); // chart horizontal line
line(23, 290, 977, 290); // chart horizontal line
line(23, 490, 977, 490); // chart horizontal line
line(23, 590, 977, 590); // chart horizontal line
stroke(0); // chart black lines
line(width/2, 106, width/2, 672); // chart center vertical line
line(7, 390, 993, 390); // chart center horizontal line
//input / output pins setup
arduino = new Arduino(this, Arduino.list()[0], 57600);
arduino.pinMode(onPin, Arduino.OUTPUT);
arduino.pinMode(hallPin, Arduino.INPUT);
}
// bottom dead center function
void bottomDeadCenter() {
arduino.digitalWrite(onPin, arduino.LOW);
int hallSensor = arduino.digitalRead(hallPin); //read hall value
while (hallSensor == arduino.HIGH) {
arduino.digitalWrite(onPin, arduino.HIGH); //if there is no magnet, turn on the motor
hallSensor = arduino.digitalRead(hallPin);
}
arduino.digitalWrite(onPin, arduino.LOW); //if there is magnet, turn off the motor
return; // stop the function
}
void draw() {
smooth();
// colors for interactive button backgrounds
int red = color(227, 23, 23);
int green = color(65, 190, 55);
int grey = color(200);
//load the font
font = loadFont("Verdana-18.vlw"); //load the font
textFont(font); //set the current text font
noStroke();
fill(190); // red buttons shadow
rect(23, 23, 120, 73);
rect(163, 23, 120, 73);
rect(303, 23, 120, 73);
stroke(170); // red buttons
strokeWeight(1);
fill(bdcColor); // BDC BUTTON
rect(20, 20, 120, 73);
fill(255);
text("BDC", 40, 65);
fill(loadCellColor); // LOAD CELL BUTTON
rect(160, 20, 120, 73);
fill(255);
text("RESET", 180, 55);
text("Load Cell", 180, 75);
fill(startColor); // START BUTTON
rect(300, 20, 120, 73);
fill(255);
text("START", 320, 65);
font = loadFont("Verdana-12.vlw");
textFont(font);
fill(46, 42, 42);
strokeWeight(0);
text("LoadCellVoltageRef", 450, 45); // INFO TEXT
text("maxVelocity", 660, 45);
text("Stroke", 850, 45);
text("maxLoad", 450, 85);
text("minLoad", 620, 85);
text("OMEGA", 850, 85);
font = loadFont("Verdana-18.vlw");
textFont(font);
//BDC BUTTON OPERATION
if (BDC == false && loadCell == false) {
if (mouseX > 20 && mouseX < 140 && mouseY > 20 && mouseY < 93) {
if (mousePressed == true && mouseButton == LEFT) { //check the button if it is pressed
bottomDeadCenter();
bdcColor = green;
loadCellColor = red;
BDC = true;
}
}
}
// LOAD CELL OPERATION
if (BDC == true && loadCell == false) {
if (mouseX > 160 && mouseX < 280 && mouseY > 20 && mouseY < 93) {
if (mousePressed == true && mouseButton == LEFT) { //check the button if it is pressed
loadCell = true;
loadCellColor = green;
startColor = red;
}
}
}
// START BUTTON OPERATION
if (BDC == true && loadCell == true) {
if (mouseX > 300 && mouseX < 420 && mouseY > 20 && mouseY < 93) {
if (mousePressed == true && mouseButton == LEFT) { //check the button if it is pressed
startColor = green;
}
}
}
}
there are other butons, but i haven't creaed functions for them yet.
also the program does not seem to respond quickly to the mouse click. It needs the longer press of the mouse button to be "clicked"
any thoughts are appretiated.
I am using windows 7, 64 bit