This is the progress of the UI so far, I am currently trying to have the crane game properly work but there were a couple of minor issues, like trying to have the rest of the buttons lock once the user chooses a button or lets go of it. I'm still going through the tinkering, but it's progressing very quickly.
//import processing.serial.*;
//import cc.arduino.*;
import controlP5.*;
//Arduino arduino;
ControlP5 cp5;
int xPos = 120; //60-180 [Free Default 120]
int yPos = 80; //60(PULLEDBACK)-150( PUSHEDFORWARD) [Free Default 80]
int elbowPos = 150; //0-180 [Free Default 150]
int clawPos = 100; //50(OPEN)-100(CLOSED) [Free Default 100]
int bg1 = 0;
int bg2 = 0;
boolean craneStart = false;
boolean craneLeft = false;
boolean craneLeftMove = false;
boolean craneForward = false;
boolean craneForwardMove = false;
boolean cranePickup = false;
boolean cranePickupMove = false;
boolean craneReset = false;
//**//**//**//**//**//
void setup() {
size(1200,800);
background(200,200,200);
//Initialize CP5 Object
cp5 = new ControlP5(this);
cp5.addButton("freeMode")
.setLabel("Activate Free Mode")
.setPosition(5,5)
.setSize(590,65)
.setColorBackground(color( 255,127,0))
.setColorForeground(color( 255,200,0))
.setColorLabel(color(0))
.setColorActive(color(255, 255,0))
;
cp5.addButton("craneMode")
.setLabel("Activate Crane Game")
.setPosition((width/2)+5,5)
.setSize(590,65)
.setColorBackground(color( 255,127,0))
.setColorForeground(color( 255,200,0))
.setColorLabel(color(0))
.setColorActive(color(255, 255,0))
;
//CRANE MODE BUTTONS
Button crane0 = cp5.addButton("cStart")
.setPosition((width/2)+5,80)
.setSize(590,65)
.setLabel("START (Click once)")
.setColorBackground(color(0, 255,0));
;
Button crane1 = cp5.addButton("cLeft")
.setPosition((width/2)+5,155)
.setSize(590,65)
.setLabel("LEFT (Press and hold)")
.setColorBackground(color(0, 255,0));
;
Button crane2 = cp5.addButton("cForward")
.setPosition((width/2)+5,230)
.setSize(590,65)
.setLabel("FORWARD (Press and hold)")
.setColorBackground(color(0, 255,0));
;
Button crane3 = cp5.addButton("cPickup")
.setPosition((width/2)+5,305)
.setSize(590,65)
.setLabel("PICK UP (Click once)")
.setColorBackground(color(0, 255,0));
;
crane0.addCallback(new CallbackListener() {
public void controlEvent(CallbackEvent theEvent) {
switch(theEvent.getAction()) {
case(ControlP5.ACTION_PRESSED) : break;
case(ControlP5.ACTION_ RELEASED): craneLeft = true; craneStart = true; break;
}
}
});
crane1.addCallback(new CallbackListener() {
public void controlEvent(CallbackEvent theEvent) {
switch(theEvent.getAction()) {
case(ControlP5.ACTION_PRESSED) : craneLeftMove = true; break;
case(ControlP5.ACTION_ RELEASED): craneForward = true; craneLeft = false; craneLeftMove = false; break;
}
}
});
crane2.addCallback(new CallbackListener() {
public void controlEvent(CallbackEvent theEvent) {
switch(theEvent.getAction()) {
case(ControlP5.ACTION_PRESSED) : craneForwardMove = true; break;
case(ControlP5.ACTION_ RELEASED): cranePickup = true; craneForward = false; craneForwardMove = false; break;
}
}
});
crane3.addCallback(new CallbackListener() {
public void controlEvent(CallbackEvent theEvent) {
switch(theEvent.getAction()) {
case(ControlP5.ACTION_PRESSED) : break;
case(ControlP5.ACTION_ RELEASED): cranePickupMove = true; cranePickup = false; craneReset = true; break;
}
}
});
//arduino = new Arduino(this, Arduino.list()[2], 57600);
//arduino.pinMode(8, Arduino.SERVO); // BASE (x movement)
//arduino.pinMode(4, Arduino.SERVO); // SHOULDER (y movement)
//arduino.pinMode(12, Arduino.SERVO); // ELBOW (elbow movement)
//arduino.pinMode(2, Arduino.SERVO); //CLAW (claw movement)
freeMode();
}
//**//**//**//**//**//
void draw() {
background(200,200,200);
noStroke();
fill(bg1);
rect(0,0,width/2,height);
fill(bg2);
rect(width/2,0,width/2,height) ;
if (craneStart) {
cp5.getController("freeMode"). lock();
cp5.getController("cStart"). hide();
setLockC(cp5.getController(" cStart"),true);
cp5.getController("cStart"). show();
setLockC(cp5.getController(" cLeft"),false);
setLockC(cp5.getController(" cForward"),true);
setLockC(cp5.getController(" cPickup"),true);
craneStart = false;
}
if (craneLeft) {
if (craneLeftMove) {
//UPDATE INT "xPos"
}
}
if (craneForward) {
cp5.getController("cLeft"). hide();
setLockC(cp5.getController(" cLeft"),true);
cp5.getController("cLeft"). show();
setLockC(cp5.getController(" cForward"),false);
if (craneForwardMove) {
//UPDATE INT "yPos"
}
}
if (cranePickup) {
cp5.getController("cForward"). hide();
setLockC(cp5.getController(" cForward"),true);
cp5.getController("cForward"). show();
setLockC(cp5.getController(" cPickup"),false);
if (cranePickupMove) {
//UPDATE run custom grab and place object movement
}
}
if(craneReset) {
cp5.getController("cPickup"). hide();
setLockC(cp5.getController(" cPickup"),true);
cp5.getController("cPickup"). show();
setLockC(cp5.getController(" cStart"),false);
cp5.getController("freeMode"). unlock();
craneReset = false;
}
/* DEBUG
println("craneStart = " + craneStart);
println("craneLeft = " + craneLeft);
println("craneLeftMove = " + craneLeftMove);
println("craneForward = " + craneForward);
println("craneForwardMove = " + craneForwardMove);
println("cranePickup = " + cranePickup);
println("cranePickupMove = " + cranePickupMove);
println("--------------------- --");
END DEBUG */
//arduino.servoWrite(8, xPos);
//arduino.servoWrite(4, yPos);
//arduino.servoWrite(12, elbow);
//arduino.servoWrite(2, clawPos);
}
//**//**//**//**//**//
void freeMode() {
bg1 = 255;
bg2 = 200;
cp5.getController("freeMode"). hide();
cp5.getController("freeMode"). lock();
cp5.getController("freeMode"). show();
cp5.getController("craneMode") .unlock();
setLockC(cp5.getController(" cStart"),true);
setLockC(cp5.getController(" cLeft"),true);
setLockC(cp5.getController(" cForward"),true);
setLockC(cp5.getController(" cPickup"),true);
}
void craneMode() {
bg1 = 200;
bg2 = 255;
cp5.getController("craneMode") .hide();
cp5.getController("craneMode") .lock();
cp5.getController("craneMode") .show();
cp5.getController("freeMode"). unlock();
setLockC(cp5.getController(" cStart"),false);
}
//To lock/unlock crane buttons...
void setLockC(Controller theController, boolean locked) {
theController.setLock(locked);
if(locked) {
theController. setColorBackground(color(255, 0,0));
} else {
theController. setColorBackground(color(0, 255,0));
}
}
https://www.youtube.com/watch?v=8XeVJL-sDNo
No comments:
Post a Comment