Let's Make Robots!

A little help with processing code...

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);
}

 if (mousePressed && (mouseButton == LEFT)) {{
    myPort.write(75);
    delay(100);
 }
  rect(275, 400, 50, 50);
 }

 if (mousePressed && (mouseButton == LEFT)) {{
    myPort.write(85);
    delay(100);
  }
  rect(200, 275, 50, 50);
}


 if (mousePressed && (mouseButton == LEFT)) {{
    myPort.write(95);
    delay(100);
  }
  rect(400, 275, 50, 50);
 }

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

for(int i=0; i <=2; i++){

print("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.");

 

but tripple-speak?
see subject for content.

This is awesome Chris! You keep expanding everyone's understanding of this stuff.

2 things (maybe already answered somewhere, but this topic is sort of all-over-the-place):

1. can we get a sample of the axe code to receive the serial commands?

2. you're using the rev-ed usb-to-serial download cable?

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.
well, you sure do drive the point about how to do this!!!!
Calculon likes
lol...still funny after the third round.  :D
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.

deja vu