Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import processing.serial.*;
- float[] portValues = new float[8];
- Serial myPort;
- String inString;
- int r = 10;
- int g = 10;
- int b = 10;
- float x=0;
- float y=0;
- float z=0;
- void setup()
- {
- size(1000,1000);
- background(255);
- myPort = new Serial(this, "/dev/cu.usbmodem1421",9600);
- for(int i = 0; i<8; i++)
- {
- portValues[i] = 0;
- }
- }
- void draw() {
- if (inString != null) {
- portValues = processSensorValues(inString);
- }
- if (portValues[3]==0 && portValues[4]==1)
- {
- frameRate(15);
- y=random(255);
- x=random(255);
- z=random(255);
- }
- fill(r,g,b);
- // Parts here were in the wrong place and used down below on the color scale and change rate, with drawing as a plus.
- //ellipseMode(CENTER);
- //ellipse(100,300,100,155);
- //fill(360,360,300);
- //rect(100,100,100,100);
- //fill(50,360,360);
- //rect(350,175,100,50);
- ////fill(,0,100);
- //rect(475,290,150,175);
- fill(r,g,b);
- strokeWeight(1);
- rect(0,0,100,12);
- fill(225);
- text((r + "," +"," + b),10,10);
- //horozontal lines
- strokeWeight(4);
- line(1000,150,0,150);
- line(1000,200,0,200);
- line(1000,50,0,50);
- line(1000,375,0,375);
- //vertical lines
- line(50,0,50,0);
- line(50,0,50,1000);
- line(150,0,150,1000);
- line(300,0,300,1000);
- line(400,0,400,1000);
- line(550,0,550,1000);
- float tempValue = map(portValues[7],77,86,0,255);
- if(portValues[3] == 1) {
- fill(255,300,0,tempValue);
- } else if(portValues[4] == 1) {
- fill(0,255,0,tempValue);
- } else {
- fill(0,0,255,tempValue);
- }
- ellipseMode(CENTER);
- ellipse(100,300,100,155);
- fill(360,360,300);
- rect(100,100,100,100);
- fill(50,360,360);
- rect(350,175,100,50);
- //fill(,0,100);
- rect(475,290,150,175);
- float x = map(portValues[1],-10,10,0,width);
- float y = map(portValues[0],-10,10,0,height);
- //float z = map(portValues[2],-10,10,50,150); // dont think I meeded to add this, mainly for drawing piece just experementing.
- float lightValue = portValues[5];
- noStroke();
- ellipse(x, y, 10, 10);
- println(inString);
- }
- void mouseDragged()// used to draw and change the thickness of lines when drawing but does not work if I turn off dots.
- {
- if(mouseButton == LEFT)
- {
- strokeWeight(20);
- stroke(r,g,b);
- line(pmouseX,pmouseY,mouseX,mouseY);
- }
- }
- void mousePressed()
- {
- if(mouseButton == RIGHT)
- {
- background(255);
- }
- }
- float[] processSensorValues(String valString) {
- String[] temp = new String[8];
- temp = split(valString,"\t");
- if(temp == null) {
- for(int i = 0; i<8; i++) {
- temp[i] = "0";
- }
- }
- float[] vals = new float[8];
- for(int i = 0; i<8; i++)
- {
- if(temp != null)
- {
- vals[i] = float(temp[i]);
- }
- else
- {
- vals[i] = 0;
- }
- }
- return vals;
- }
- void serialEvent(Serial p) {
- inString = myPort.readStringUntil(10);
- }
Add Comment
Please, Sign In to add comment