Last active
August 29, 2015 14:01
-
-
Save artbikes/eff4ac9bc7f4b1d6a333 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import processing.serial.*; //we need the use of this library to communicate with the serial port | |
Serial myPort; // Create object from Serial class | |
//these are the diffent messages that we will send to the sign, remeber the sign has a protocol | |
String message0 = "<ID01>"; //wake up call | |
String message1 = "<ID01><PA><FQ><CC>Red Box "; //command for sign number 1, page 1, make text appear and stop , red colour font with the message 'red box' | |
String message2 = "<ID01><PA><FQ><CL>Green Box ";//same as above but colour of text is green as is the message | |
String message3 = "<ID01><PA><FL><CC> ";//clear screen by dropping away like rain. | |
char character; //we will send one charater at a time this is the place holder | |
void setup() | |
{ | |
size(200, 200); | |
// I know that the first port in the serial list on | |
//the machine running the Prolite is the serial port we need. | |
String portName = Serial.list()[0]; | |
myPort = new Serial(this, portName, 9600); | |
} | |
void draw() { | |
background(255); | |
callSign(); | |
fill(255,0,0); | |
rect(20, 20, 50, 50); | |
fill(0,255,0); | |
rect(90, 20, 50, 50); | |
} | |
boolean mouseOverRect() { // Test if mouse is over square | |
return ((mouseX >= 20) && (mouseX <= 70) && (mouseY >= 20) && (mouseY <= 70)); | |
} | |
boolean mouseOverRect2() { // Test if mouse is over square | |
return ((mouseX >= 90) && (mouseX <= 140) && (mouseY >= 20) && (mouseY <= 70)); | |
} | |
void callSign(){ | |
for(int i = 0;i<=message0.length()-1;i++){ | |
character = message0.charAt(i); | |
myPort.write(byte(character)); //wake up the sign | |
} | |
myPort.write(13); //end of line | |
myPort.write(10); // carriage return | |
delay(30); | |
} | |
void mousePressed(){ | |
for(int i = 0;i<=message3.length()-1;i++){ | |
character = message3.charAt(i); | |
myPort.write(byte(character)); //clear the screen when mouse is clicked | |
} | |
myPort.write(13); //end of line | |
myPort.write(10); //carriage return | |
delay(500); | |
if (mouseOverRect() == true) { // If mouse is over the red square, | |
fill(255,100,100); // change color and | |
rect(20, 20, 50, 50); | |
for(int i = 0;i<=message1.length()-1;i++){ | |
character = message1.charAt(i); | |
myPort.write(byte(character)); //update sign with message 1 | |
} | |
myPort.write(13); //end of line | |
myPort.write(10); //carriage return | |
} | |
if (mouseOverRect2() == true){ // If mouse is over the green square, | |
fill(100,255,100); // change color | |
rect(90, 20, 50, 20); //redraw to screen | |
for(int i = 0;i<=message2.length()-1;i++){ | |
character = message2.charAt(i); | |
myPort.write(byte(character)); // send message 2 | |
} | |
myPort.write(13); //end of line | |
myPort.write(10); //carriage return | |
} | |
delay(30); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment