« sources for electronics components | Main | The McVoting Booth »
October 19, 2004
Processing and BS2
I'm trying to get Processing to read a binary input, here is the reference code:
// Binary Input
// by Mathias Dahlstrom
// Example of a binary input from a BX-24 chip using serial communcation.
// Running this examples requires you have a BX-24 microcontroller
// and peripheral hardware. More information can be found on the tutorial
// pages of Tom Igoe: http://stage.itp.nyu.edu/%7Etigoe/pcomp/examples.shtml
// Make sure to have the correct port selected in the "sketch" menu. Because
// this program uses the serial port, it will not work within a web browser.
// Created 12 February 2003
// State of the circle drawing
boolean circleExpanding = true;
// Size of the circle
float circleSize = 0;
//The setup defines screen size and color setup.
void setup()
{
size(200, 200);
beginSerial(19200);
noStroke();
fill(204);
ellipseMode(CENTER_RADIUS);
}
// The loop checks for what state the circle should be
// drawn into and performs the drawing.
void loop()
{
background(0);
if(circleExpanding) {
ellipse(width/2, height/2, circleSize, circleSize);
circleSize += 0.5;
}else{
ellipse(width/2, height/2, circleSize, circleSize);
circleSize -= 0.5;
}
if(circleSize > width/2) {
circleSize = width/2;
}
if(circleSize < 10) {
circleSize = 10;
}
}
// Function is called when ever a new byte from the
// BX-24 is avaliable for reading.
// It controls what input the user is generating and
// sets the corresponding drawing mode.
void serialEvent()
{
// Checks the ASCII code sent from the basicX chip.
// '48' is the code for '0' and '49' is the code for '1'
if(serial == 0) {
circleExpanding = false;
}
if(serial == 1) {
circleExpanding = true;
}
println(serial);
}
*******************************
Here is my code for BS2:
SerInPin PIN 0 'serial IN pin (RXD - at the other end: TXD)
SerOutPin PIN 1 'serial OUT pin (TXD - at the other end: RXD)
SerInData VAR BYTE 'number to match to incoming data
SerWait CON 50 'ms to wait for input before timing out
N9600 CON 16468 'BS2 baudmode values: 16468/9600, 16416/19200, 16390/38400
'See SEROUT in the Basic Stamp manual for details.
DEBUG CR,"Program starting ...",CR
test:
IF IN2 THEN
HIGH 11
SEROUT SerOutPin,N9600,[DEC 1,CR]
DEBUG "1"
ELSE
LOW 11
SEROUT SerOutPin,N9600,[DEC 0,CR]
DEBUG "0"
ENDIF
GOTO test
************************************
But everytime I run the Processing program, it just makes a circle that expands. Blah!
Posted by kellee at October 19, 2004 03:07 PM
Comments
solution: put a PAUSE into the BS2 script before the GOTO. The problem was it was sending info too fast for processing to pick up.
Posted by: kellee at October 19, 2004 03:44 PM
Post a comment
Thanks for signing in, . Now you can comment. (sign out)
(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)