Back to Parent

import processing.serial.*;

import cc.arduino.*;

import controlP5.*;

import processing.serial.*;//引入serial

Serial myPort;
//Arduino arduino;

ControlP5 cp5;

int spend = 0;
int save = 0;

int buget = 0;

int range = 1000;

Knob myKnobA;
Knob myKnobB;
Knob myKnobC;
void setup() {
 size(500, 800);
  println(Arduino.list());
 
// arduino = new Arduino(this,"/dev/cu.usbmodem1411", 9600);
  myPort = new Serial(this, "/dev/cu.usbmodem1421", 9600);
 
  cp5 = new ControlP5(this);


    
    
    
  myKnobA =   cp5.addKnob("Buget")
              .setRange(0,range)
              .setValue(75)
              .setPosition(210,350)
              .setRadius(50)
              .setDragDirection(Knob.VERTICAL)
              ;
              
         myKnobB =           cp5.addKnob("Spend")
              .setRange(0,range*0.75)
              .setValue(100)
              .setPosition(210,150)
              .setRadius(50)
              .setDragDirection(Knob.VERTICAL)
              ;
              
          myKnobC =  cp5.addKnob("Save")
              .setRange(0,range*0.25)
              .setValue(25)
              .setPosition(210,600)
              .setRadius(50)
              .setDragDirection(Knob.VERTICAL)
              ;
      // arduino.pinMode(9, Arduino.OUTPUT);
       //arduino.pinMode(10, Arduino.OUTPUT);
       //arduino.pinMode(11, Arduino.OUTPUT);
       
}
 
 
 void draw() {
   int buget = (int)(cp5.get(Knob.class,"Buget").getValue());
  
    myKnobB.setValue(myKnobA.getValue()*0.75);
    myKnobC.setValue(myKnobA.getValue()*0.25);
    
    spend = (int)myKnobB.getValue();
    save = (int)myKnobC.getValue();
    textSize(20);
    noStroke();
   fill((int)(spend/2.9),60,60);
   rect(0,0, 500,400);
   fill(255,255,255);
   text("SPEND:" + String.valueOf(spend), 220, 140);
   fill(60,(int)(save/0.98),60);
   rect(0,400, 500,400);
   fill(255,255,255);
   text("SAVE:" + String.valueOf(save), 220, 580);
   //delay(100);
   
   //arduino.analogWrite(9, (int)(spend/2.9));
   //arduino.analogWrite(10, 105);
   //arduino.analogWrite(11, 255);
   //println((int)(spend/2.97)+"\n");
   String d = (int)(spend*1.2)+"\n";
  myPort.write(d);
   
 }
Click to Expand

Content Rating

Is this a good/useful/informative piece of content to include in the project? Have your say!

0