Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /****************************************"
- IM-Press Technologies - By Paul D'Intino
- (C)Copyright 2011
- Sensor Array Test ver 2.0
- With HEAPS of help from Taha Bintahir =)
- ****************************************/
- import processing.serial.*;
- Serial myPort;
- PFont font; // The display font:
- String inString; // Input string from serial port:
- // int[] SerialInArray = {0,0,0,0,0,0,0,0}; //clear the output
- int Width = 600;
- int Height = 600;
- String Buff = null; // Data in Buffer
- byte[][] serialInArray = new byte[4][8]; // Where we'll put what we receive
- int serialCount = 0; // A count of how many bytes we receive
- boolean firstContact = false; // Whether we've heard from the microcontroller
- int limitvalue = 1;
- int strokewidth = 1;
- //Initialise Sensor Width/Height
- int SensorWidth = 20;
- int SensorHeight = 20;
- void setup () {
- size(Width, Height);
- println(Serial.list());
- myPort = new Serial(this, Serial.list()[1], 115200);
- //myPort.bufferUntil('\n');
- println("****************************************");
- println("IM-Press Technologies - By Paul D'Intino");
- println("(C)Copyright 2011");
- println("Sensor Array Test ver 1.0");
- println("****************************************");
- //println("");
- println("DEBUG SCREEN");
- println("============");
- //println("Number of Sensors = " + NumberOfSensors);
- println("Initializing Sensors...");
- println("Font Selected: " + PFont.list()[431]);
- //background (255);
- frameRate(45); //max 40-45fps before flickering occurs
- //smooth(); //looks better but slows down performance
- }
- void draw () {
- background (0);
- clearArray();
- serialInArray = readByte();
- font = createFont(PFont.list()[431],12);
- //fill(70,255,70); //Matrix Green
- fill(200,70,70);
- textFont(font);
- text("IM-Press Technologies", 30,40);
- text("By Paul D'Intino", 30,60);
- text("(C)Copyright 2011", 30,80);
- text("Sensor Array Test ver 2.0", 390,40);
- text("Received: " + serialInArray[0] + ","
- + serialInArray[1] + ","
- + serialInArray[2] + ","
- + serialInArray[3] + ","
- + serialInArray[4] + ","
- + serialInArray[5] + ","
- + serialInArray[6] + ","
- + serialInArray[7] + ",", 30,570);// 30,570);
- updateWindow();
- //Draw the border modules
- /*-----------------------*/
- //noStroke();
- stroke(0);
- strokeWeight(1);
- //fill(152,251,152); //Pale Green
- //fill(135,206,250); //Light Sky Blue
- //fill(0,191,255); //Deep Sky Blue
- fill(0,255,127); //Spring Green
- //rect(x,y,width,height);
- rect(20,0,560,20); //Top
- rect(0,20,20,560); //Left
- rect(20,580,560,20); //Bottom
- rect(580,20,20,560); //Right
- //Draw IR LED's
- /*-------------*/
- //IR LED Top
- fill(200); //Spring Green
- rect(width/2-10,0,SensorWidth,SensorHeight);
- //IR LED Top Left
- fill(80); //Spring Green
- rect(width/2-width/4-10,0,SensorWidth,SensorHeight);
- //IR LED Top Right
- fill(80); //Spring Green
- rect(width/2+width/4-10,0,SensorWidth,SensorHeight);
- //IR LED Right
- fill(200); //Spring Green
- rect(width-20,height/2-10,SensorWidth,SensorHeight);
- //IR LED Right Top
- fill(80); //Spring Green
- rect(width-20,height/2-height/4-10,SensorWidth,SensorHeight);
- //IR LED Right Bottom
- fill(80); //Spring Green
- rect(width-20,height/2+height/4-10,SensorWidth,SensorHeight);
- //IR LED Bottom
- fill(200); //Spring Green
- rect(width/2-10,height-20,SensorWidth,SensorHeight);
- //IR LED Bottom Left
- fill(80); //Spring Green
- rect(width/2-width/4-10,height-20,SensorWidth,SensorHeight);
- //IR LED Bottom right
- fill(80); //Spring Green
- rect(width/2+width/4-10,height-20,SensorWidth,SensorHeight);
- //IR LED Left
- fill(200); //Spring Green
- rect(0,height/2-10,SensorWidth,SensorHeight);
- //IR LED Left Top
- fill(80); //Spring Green
- rect(0,height/2-height/4-10,SensorWidth,SensorHeight);
- //IR LED Left Bottom
- fill(80); //Spring Green
- rect(0,height/2+height/4-10,SensorWidth,SensorHeight);
- }
- void clearArray()
- {
- for(int h = 0; h < 4; h++){
- for(int i = 0; i < 8; i++){
- serialInArray[h][i] = 100;
- }
- }
- }
- byte [][] readByte()
- {
- byte[] tempData = new byte[8];
- byte[][] tempFrame = new byte [4][8];
- int noBytesRead = 0;
- int count = 0
- while(myPort.available() > 0){
- if(firstContact == false){
- int inByte = myPort.read();
- if(inByte == 'A'){
- myPort.clear();
- myPort.write('A');
- firstContact = true;
- noBytesRead = myPort.readBytes(tempData);
- }
- }
- else{
- myPort.write('A');
- noBytesRead = myPort.readBytes(tempData);
- }
- for(int i = 0; i < 7; i++){
- tempFrame[count][i] = tempData[i];
- }
- count++;
- if(count > 4){
- break;
- }
- }
- // return tempData;
- }
- void updateWindow(){
- /*
- //Print Array for test purposes
- print(serialInArray[0]);
- print(serialInArray[1]);
- print(serialInArray[2]);
- print(serialInArray[3]);
- print(serialInArray[4]);
- print(serialInArray[5]);
- print(serialInArray[6]);
- println(serialInArray[7]);
- */
- int xPos = 67; //originally 50
- int yPos = 67; //originally 50
- //Top Sensors - Bottom IR LED
- for(int i = 0; i < 8; i++){
- int movingXPos = xPos*(i+1);
- int movingYPos = yPos*(i+1);
- if(serialInArray[i] >=limitvalue){
- }
- else{
- stroke(255);
- //stroke(255,255,0); // YELLOW
- strokeWeight(strokewidth);
- //line (x1,y1,newX, height of sketch- number)
- //line(width/2, height, movingXPos, 0); //original
- line(width/2, height, movingXPos, 0); // TOP
- line(width/2, height, 0, movingYPos); // LEFT
- line(width/2, height, height, movingYPos); //RIGHT
- }
- }
- //Top Sensors - Bottom Left IR LED
- for(int i = 0; i < 8; i++){
- int movingXPos = xPos*(i+1);
- int movingYPos = yPos*(i+1);
- if(serialInArray[i] >=limitvalue){
- }
- else{
- stroke(255);
- //stroke(255,255,0); // YELLOW
- strokeWeight(strokewidth);
- //line (x1,y1,newX, height of sketch- number)
- //line(width/2, height, movingXPos, 0); //original
- line(width/2-width/4, height, movingXPos, 0); // TOP
- line(width/2-width/4, height, 0, movingYPos); // LEFT
- line(width/2-width/4, height, height, movingYPos); //RIGHT
- }
- }
- //Top Sensors - Bottom Right IR LED
- for(int i = 0; i < 8; i++){
- int movingXPos = xPos*(i+1);
- int movingYPos = yPos*(i+1);
- if(serialInArray[i] >=limitvalue){
- }
- else{
- stroke(255);
- //stroke(255,255,0); // YELLOW
- strokeWeight(strokewidth);
- //line (x1,y1,newX, height of sketch- number)
- //line(width/2, height, movingXPos, 0); //original
- line(width/2+width/4, height, movingXPos, 0); // TOP
- line(width/2+width/4, height, 0, movingYPos); // LEFT
- line(width/2+width/4, height, height, movingYPos); //RIGHT
- }
- }
- //Bottom Sensors - Top IR LED
- for(int i = 0; i < 8; i++){
- int movingXPos = xPos*(i+1);
- int movingYPos = yPos*(i+1);
- if(serialInArray[i] >=limitvalue){
- }
- else{
- stroke(255);
- //stroke(255,0,0); // RED
- strokeWeight(strokewidth);
- //line (x1,y1,newX, height of sketch- number)
- //line(width/2, 0, movingXPos, height); //original
- line(width/2, 0, movingXPos, height); // BOTTOM
- line(width/2, 0, 0, movingYPos); // LEFT
- line(width/2, 0, height, movingYPos); //RIGHT
- }
- }
- //Bottom Sensors - Top Left IR LED
- for(int i = 0; i < 8; i++){
- int movingXPos = xPos*(i+1);
- int movingYPos = yPos*(i+1);
- if(serialInArray[i] >=limitvalue){
- }
- else{
- stroke(255);
- //stroke(255,0,0); // RED
- strokeWeight(strokewidth);
- //line (x1,y1,newX, height of sketch- number)
- //line(width/2, 0, movingXPos, height); //original
- line(width/2-width/4, 0, movingXPos, height); // BOTTOM
- line(width/2-width/4, 0, 0, movingYPos); // LEFT
- line(width/2-width/4, 0, height, movingYPos); //RIGHT
- }
- }
- //Bottom Sensors - Top Right IR LED
- for(int i = 0; i < 8; i++){
- int movingXPos = xPos*(i+1);
- int movingYPos = yPos*(i+1);
- if(serialInArray[i] >=limitvalue){
- }
- else{
- stroke(255);
- //stroke(255,0,0); // RED
- strokeWeight(strokewidth);
- //line (x1,y1,newX, height of sketch- number)
- //line(width/2, 0, movingXPos, height); //original
- line(width/2+width/4, 0, movingXPos, height); // BOTTOM
- line(width/2+width/4, 0, 0, movingYPos); // LEFT
- line(width/2+width/4, 0, height, movingYPos); //RIGHT
- }
- }
- //Right Sensors - Left IR LED
- for(int i = 0; i < 8; i++){
- int movingXPos = xPos*(i+1);
- int movingYPos = yPos*(i+1);
- if(serialInArray[i] >=limitvalue){
- }
- else{
- stroke(255);
- //stroke(0,0,255); // BLUE
- strokeWeight(strokewidth);
- //line (x1,y1,newX, height of sketch- number)
- //line(0, height/2, height, movingYPos); //original
- line(0, height/2, height, movingYPos); // RIGHT
- line(0, height/2, movingXPos, height); // BOTTOM
- line(0, height/2, movingXPos, 0); // TOP
- }
- }
- //Right Sensors - Left Top IR LED
- for(int i = 0; i < 8; i++){
- int movingXPos = xPos*(i+1);
- int movingYPos = yPos*(i+1);
- if(serialInArray[i] >=limitvalue){
- }
- else{
- stroke(255);
- //stroke(0,0,255); // BLUE
- strokeWeight(strokewidth);
- //line (x1,y1,newX, height of sketch- number)
- //line(0, height/2, height, movingYPos); //original
- line(0, height/2-height/4, height, movingYPos); // RIGHT
- line(0, height/2-height/4, movingXPos, height); // BOTTOM
- line(0, height/2-height/4, movingXPos, 0); // TOP
- }
- }
- //Right Sensors - Left Bottom IR LED
- for(int i = 0; i < 8; i++){
- int movingXPos = xPos*(i+1);
- int movingYPos = yPos*(i+1);
- if(serialInArray[i] >=limitvalue){
- }
- else{
- stroke(255);
- //stroke(0,0,255); // BLUE
- strokeWeight(strokewidth);
- //line (x1,y1,newX, height of sketch- number)
- //line(0, height/2, height, movingYPos); //original
- line(0, height/2+height/4, height, movingYPos); // RIGHT
- line(0, height/2+height/4, movingXPos, height); // BOTTOM
- line(0, height/2+height/4, movingXPos, 0); // TOP
- }
- }
- //Left Sensors - Right IR LED
- for(int i = 0; i < 8; i++){
- int movingXPos = xPos*(i+1);
- int movingYPos = yPos*(i+1);
- if(serialInArray[i] >=limitvalue){
- }
- else{
- stroke(255);
- //stroke(0,255,0); // GREEN
- strokeWeight(strokewidth);
- //line (x1,y1,newX, height of sketch- number)
- //line(width, height/2, 0, movingYPos); //original
- line(width, height/2, 0, movingYPos); // LEFT
- line(width, height/2, movingXPos, height); // BOTTOM
- line(width, height/2, movingXPos, 0); // TOP
- }
- }
- //Left Sensors - Right Top IR LED
- for(int i = 0; i < 8; i++){
- int movingXPos = xPos*(i+1);
- int movingYPos = yPos*(i+1);
- if(serialInArray[i] >=limitvalue){
- }
- else{
- stroke(255);
- //stroke(0,255,0); // GREEN
- strokeWeight(strokewidth);
- //line (x1,y1,newX, height of sketch- number)
- //line(width, height/2, 0, movingYPos); //original
- line(width, height/2-height/4, 0, movingYPos); // LEFT
- line(width, height/2-height/4, movingXPos, height); // BOTTOM
- line(width, height/2-height/4, movingXPos, 0); // TOP
- }
- }
- //Left Sensors - Right Bottom IR LED
- for(int i = 0; i < 8; i++){
- int movingXPos = xPos*(i+1);
- int movingYPos = yPos*(i+1);
- if(serialInArray[i] >=limitvalue){
- }
- else{
- stroke(255);
- //stroke(0,255,0); // GREEN
- strokeWeight(strokewidth);
- //line (x1,y1,newX, height of sketch- number)
- //line(width, height/2, 0, movingYPos); //original
- line(width, height/2+height/4, 0, movingYPos); // LEFT
- line(width, height/2+height/4, movingXPos, height); // BOTTOM
- line(width, height/2+height/4, movingXPos, 0); // TOP
- }
- }
- }
Add Comment
Please, Sign In to add comment