alright I started with some sample code and it worked great -- I was able to left and right click on the square and send one of 2bytes via serial to my picaxe board. Here is the sample code:
import processing.serial.*; Serial myPort; void setup(){ // Click within the image and press // the left and right mouse buttons to // change the value of the rectangle myPort = new Serial(this, "COM15", 9600); } void draw() { if (mousePressed && (mouseButton == LEFT)) { myPort.write(65); delay(100); } else if (mousePressed && (mouseButton == RIGHT)) { myPort.write(70);
} rect(25, 25, 50, 50); }
Now i am trying to expand on this to 4 squares and sending 4 different bytes with a left click on each square. However, I simply can't figure out how the code connects the square that is drawn to the click that pertains to it. I would assume it has to do with what things are included in the { }'s but man, I am stumped. Any thoughts? Here is my feeble attempt at it:
import processing.serial.*; Serial myPort; void setup(){ size(600,600); // Click within the image and press // the left and right mouse buttons to // change the value of the rectangle myPort = new Serial(this, "COM15", 9600); } void draw() { if (mousePressed && (mouseButton == LEFT)) {{ myPort.write(65); delay(100); } rect(275, 200, 50, 50); }
This example had a HUGE disadvantage. You need to define each rectangle AND then you must also put the effective coordinates of each rectangle in a separate if/then condition. Blech.
void setup(){ size(600,600); } void draw() { rect(275, 200, 50, 50); // rect A rect(275, 400, 50, 50); // rect B rect(200, 275, 50, 50); // rect C rect(400, 275, 50, 50); // rect um
I modified the code to use a conditional to reduce the amount of coded needed…works great…just replace the println with what you want to do. myport.write command and such
void mousePressed() { if (mouseX > x && mouseX < x+w && mouseY > y && mouseY < y+h) { clicked = (mouseButton == LEFT) ? 85:95; println(clicked); } }
EDIT: As a side note, this does not check for a center button click. it’s left otherwise right or center button would do the same thing.
Full code
//LOTS OF SQUARES!!! boolean button = false; int clicked = 0; int x1 = 20; int y1 = 20; int w1 = 50; int h1 = 35;
int x2 = 80; int y2 = 20; int w2 = 50; int h2 = 35;
Theres a link to a gui library, is that what you are looking for?
If its not or you are looking for how to write your own you would need to place squares on the screen using the coordinates to place them, and then write something to detect when the mouse is clicked over it.
Pretty simple actually The picaxe is simply receiving bytes via serial. I could use serin but I decided just to use the regular ol’ sync cable (seeing that it is already plugged in and all) and used serrxd instead. The command is serrxd b1 --that’s it. Now you have a variable (b1) that you can use for anything you want. And yes, I am using the sync cable and a USB/serial adapter.
Pretty simple actually The picaxe is simply receiving bytes via serial. I could use serin but I decided just to use the regular ol’ sync cable (seeing that it is already plugged in and all) and used serrxd instead. The command is serrxd b1 --that’s it. Now you have a variable (b1) that you can use for anything you want. And yes, I am using the sync cable and a USB/serial adapter.
Pretty simple actually The picaxe is simply receiving bytes via serial. I could use serin but I decided just to use the regular ol’ sync cable (seeing that it is already plugged in and all) and used serrxd instead. The command is serrxd b1 --that’s it. Now you have a variable (b1) that you can use for anything you want. And yes, I am using the sync cable and a USB/serial adapter.
Awesome, Edgee!!! What an amazing bunch of data!!! Thank you so much for this, I am already going through some of the buttons and sliders for my “control panel”. Awesome!!!