ControlP5 help
in
Contributed Library Questions
•
8 months ago
I'm trying to write code using Processing editor to control my robot. I'm using the ControlP5 library to create an user interface let lets me click on buttons to control my robot. How do I get the walking code to loop after clicking on the button? The walking code plays once after clicking on the button.
[code]
import controlP5.*;
ControlP5 cp5;
int myColor = color(255);
int c1,c2;
float n,n1;
import processing.serial.*;
Serial myPort;
void setup()
{
size(700,400);
noStroke();
cp5 = new ControlP5(this);
cp5.addButton("Stand").setValue(0).setPosition(100,100).setSize(100,20);
cp5.addButton("Sit").setValue(0).setPosition(100,130).setSize(100,20);
cp5.addButton("Squat").setValue(0).setPosition(100,160).setSize(100,20);
cp5.addButton("Walk").setValue(0).setPosition(100,190).setSize(100,20);
String portName = Serial.list()[0];
myPort = new Serial(this, portName, 115200);
myPort.write("#0 P1500 T0 \r ");
myPort.write("#1 P1500 T0 \r ");
myPort.write("#2 P1500 T0 \r ");
myPort.write("#3 P1500 T0 \r ");
myPort.write("#4 P1500 T0 \r ");
myPort.write("#5 P1500 T0 \r ");
myPort.write("#6 P1500 T0 \r ");
myPort.write("#7 P1500 T0 \r ");
myPort.write("#8 P1500 T0 \r ");
myPort.write("#9 P1500 T0 \r ");
myPort.write("#10 P1500 T0 \r ");
myPort.write("#11 P1500 T0 \r ");
myPort.write("#12 P500 T0 \r ");
myPort.write("#13 P2500 T0 \r ");
myPort.write("#14 P1500 T0 \r ");
myPort.write("#15 P1500 T0 \r ");
myPort.write("#16 P1500 T0 \r ");
myPort.write("#17 P1500 T0 \r ");
myPort.write("#18 P1500 T0 \r ");
myPort.write("#19 P1500 T0 \r ");
myPort.write("#20 P1900 T0 \r ");
myPort.write("#21 P1900 T0 \r ");
myPort.write("#22 P1500 T0 \r ");
myPort.write("#23 P1500 T0 \r ");
}
void draw()
{
background(0);
fill(255);
}
void robotstand01()
{
myPort.write("#0 P1500 T10 \r ");
myPort.write("#1 P1500 T10 \r ");
myPort.write("#2 P1500 T10 \r ");
myPort.write("#3 P1500 T10 \r ");
myPort.write("#4 P1500 T10 \r ");
myPort.write("#5 P1500 T10 \r ");
myPort.write("#6 P1500 T10 \r ");
myPort.write("#7 P1500 T10 \r ");
myPort.write("#8 P1500 T10 \r ");
myPort.write("#9 P1500 T10 \r ");
myPort.write("#10 P1500 T10 \r ");
myPort.write("#11 P1500 T10 \r ");
myPort.write("#12 P500 T10 \r ");
myPort.write("#13 P2500 T10 \r ");
myPort.write("#14 P1500 T10 \r ");
myPort.write("#15 P1500 T10 \r ");
myPort.write("#16 P1500 T10 \r ");
myPort.write("#17 P1500 T10 \r ");
myPort.write("#18 P1500 T10 \r ");
myPort.write("#19 P1500 T10 \r ");
myPort.write("#20 P1900 T10 \r ");
myPort.write("#21 P1900 T10 \r ");
myPort.write("#22 P1500 T10 \r ");
myPort.write("#23 P1500 T10 \r ");
}
void robotsit01()
{
myPort.write("#0 P1500 T10 \r ");
myPort.write("#1 P1500 T10 \r ");
myPort.write("#2 P1500 T10 \r ");
myPort.write("#3 P1500 T10 \r ");
myPort.write("#4 P1000 T10 \r ");
myPort.write("#5 P2000 T10 \r ");
myPort.write("#6 P2000 T10 \r ");
myPort.write("#7 P1000 T10 \r ");
myPort.write("#8 P2500 T10 \r ");
myPort.write("#9 P500 T10 \r ");
myPort.write("#10 P1500 T10 \r ");
myPort.write("#11 P1500 T10 \r ");
myPort.write("#12 P500 T10 \r ");
myPort.write("#13 P2500 T10 \r ");
myPort.write("#14 P1500 T10 \r ");
myPort.write("#15 P1500 T10 \r ");
myPort.write("#16 P1500 T10 \r ");
myPort.write("#17 P1500 T10 \r ");
myPort.write("#18 P1500 T10 \r ");
myPort.write("#19 P1500 T10 \r ");
myPort.write("#20 P1900 T10 \r ");
myPort.write("#21 P1900 T10 \r ");
myPort.write("#22 P1500 T10 \r ");
myPort.write("#23 P1500 T10 \r ");
}
void robotsquat01()
{
myPort.write("#0 P1500 T10 \r ");
myPort.write("#1 P1500 T10 \r ");
myPort.write("#2 P500 T10 \r ");
myPort.write("#3 P2500 T10 \r ");
myPort.write("#4 P500 T10 \r ");
myPort.write("#5 P2500 T10 \r ");
myPort.write("#6 P2500 T10 \r ");
myPort.write("#7 P500 T10 \r ");
myPort.write("#8 P2500 T10 \r ");
myPort.write("#9 P500 T10 \r ");
myPort.write("#10 P1500 T10 \r ");
myPort.write("#11 P1500 T10 \r ");
myPort.write("#12 P500 T10 \r ");
myPort.write("#13 P2500 T10 \r ");
myPort.write("#14 P1500 T10 \r ");
myPort.write("#15 P1500 T10 \r ");
myPort.write("#16 P1500 T10 \r ");
myPort.write("#17 P1500 T10 \r ");
myPort.write("#18 P1500 T10 \r ");
myPort.write("#19 P1500 T10 \r ");
myPort.write("#20 P1900 T10 \r ");
myPort.write("#21 P1900 T10 \r ");
myPort.write("#22 P1500 T10 \r ");
myPort.write("#23 P1500 T10 \r ");
}
void robotwalk01()
{
myPort.write("#0 P1500 T1000 \r ");
myPort.write("#1 P1500 T1000 \r ");
myPort.write("#2 P1250 T1000 \r ");
myPort.write("#3 P1250 T1000 \r ");
myPort.write("#4 P1500 T1000 \r ");
myPort.write("#5 P1500 T1000 \r ");
myPort.write("#6 P1500 T1000 \r ");
myPort.write("#7 P1500 T1000 \r ");
myPort.write("#8 P1250 T1000 \r ");
myPort.write("#9 P1250 T1000 \r ");
myPort.write("#10 P1500 T1000 \r ");
myPort.write("#11 P1500 T1000 \r ");
myPort.write("#12 P500 T1000 \r ");
myPort.write("#13 P2500 T1000 \r ");
myPort.write("#14 P1500 T1000 \r ");
myPort.write("#15 P1500 T1000 \r ");
myPort.write("#16 P1500 T1000 \r ");
myPort.write("#17 P1500 T1000 \r ");
myPort.write("#18 P1500 T1000 \r ");
myPort.write("#19 P1500 T1000 \r ");
myPort.write("#20 P1900 T1000 \r ");
myPort.write("#21 P1900 T1000 \r ");
myPort.write("#22 P1500 T1000 \r ");
myPort.write("#23 P1500 T1000 \r ");
}
void robotwalk02()
{
myPort.write("#0 P1500 T1000 \r ");
myPort.write("#1 P1500 T1000 \r ");
myPort.write("#2 P1750 T1000 \r ");
myPort.write("#3 P1750 T1000 \r ");
myPort.write("#4 P1500 T1000 \r ");
myPort.write("#5 P1500 T1000 \r ");
myPort.write("#6 P1500 T1000 \r ");
myPort.write("#7 P1500 T1000 \r ");
myPort.write("#8 P1750 T1000 \r ");
myPort.write("#9 P1750 T1000 \r ");
myPort.write("#10 P1500 T1000 \r ");
myPort.write("#11 P1500 T1000 \r ");
myPort.write("#12 P500 T1000 \r ");
myPort.write("#13 P2500 T1000 \r ");
myPort.write("#14 P1500 T1000 \r ");
myPort.write("#15 P1500 T1000 \r ");
myPort.write("#16 P1500 T1000 \r ");
myPort.write("#17 P1500 T1000 \r ");
myPort.write("#18 P1500 T1000 \r ");
myPort.write("#19 P1500 T1000 \r ");
myPort.write("#20 P1900 T1000 \r ");
myPort.write("#21 P1900 T1000 \r ");
myPort.write("#22 P1500 T1000 \r ");
myPort.write("#23 P1500 T1000 \r ");
}
public void controlEvent(ControlEvent theEvent)
{
n = 0;
}
public void Stand(int theValue)
{
robotstand01();
}
public void Sit(int theValue)
{
robotsit01();
}
public void Squat(int theValue)
{
robotsquat01();
}
public void Walk(int theValue)
{
robotwalk01();
delay(1000);
robotwalk02();
delay(1000);
redraw();
}
[/code]
ControlP5 cp5;
int myColor = color(255);
int c1,c2;
float n,n1;
import processing.serial.*;
Serial myPort;
void setup()
{
size(700,400);
noStroke();
cp5 = new ControlP5(this);
cp5.addButton("Stand").setValue(0).setPosition(100,100).setSize(100,20);
cp5.addButton("Sit").setValue(0).setPosition(100,130).setSize(100,20);
cp5.addButton("Squat").setValue(0).setPosition(100,160).setSize(100,20);
cp5.addButton("Walk").setValue(0).setPosition(100,190).setSize(100,20);
String portName = Serial.list()[0];
myPort = new Serial(this, portName, 115200);
myPort.write("#0 P1500 T0 \r ");
myPort.write("#1 P1500 T0 \r ");
myPort.write("#2 P1500 T0 \r ");
myPort.write("#3 P1500 T0 \r ");
myPort.write("#4 P1500 T0 \r ");
myPort.write("#5 P1500 T0 \r ");
myPort.write("#6 P1500 T0 \r ");
myPort.write("#7 P1500 T0 \r ");
myPort.write("#8 P1500 T0 \r ");
myPort.write("#9 P1500 T0 \r ");
myPort.write("#10 P1500 T0 \r ");
myPort.write("#11 P1500 T0 \r ");
myPort.write("#12 P500 T0 \r ");
myPort.write("#13 P2500 T0 \r ");
myPort.write("#14 P1500 T0 \r ");
myPort.write("#15 P1500 T0 \r ");
myPort.write("#16 P1500 T0 \r ");
myPort.write("#17 P1500 T0 \r ");
myPort.write("#18 P1500 T0 \r ");
myPort.write("#19 P1500 T0 \r ");
myPort.write("#20 P1900 T0 \r ");
myPort.write("#21 P1900 T0 \r ");
myPort.write("#22 P1500 T0 \r ");
myPort.write("#23 P1500 T0 \r ");
}
void draw()
{
background(0);
fill(255);
}
void robotstand01()
{
myPort.write("#0 P1500 T10 \r ");
myPort.write("#1 P1500 T10 \r ");
myPort.write("#2 P1500 T10 \r ");
myPort.write("#3 P1500 T10 \r ");
myPort.write("#4 P1500 T10 \r ");
myPort.write("#5 P1500 T10 \r ");
myPort.write("#6 P1500 T10 \r ");
myPort.write("#7 P1500 T10 \r ");
myPort.write("#8 P1500 T10 \r ");
myPort.write("#9 P1500 T10 \r ");
myPort.write("#10 P1500 T10 \r ");
myPort.write("#11 P1500 T10 \r ");
myPort.write("#12 P500 T10 \r ");
myPort.write("#13 P2500 T10 \r ");
myPort.write("#14 P1500 T10 \r ");
myPort.write("#15 P1500 T10 \r ");
myPort.write("#16 P1500 T10 \r ");
myPort.write("#17 P1500 T10 \r ");
myPort.write("#18 P1500 T10 \r ");
myPort.write("#19 P1500 T10 \r ");
myPort.write("#20 P1900 T10 \r ");
myPort.write("#21 P1900 T10 \r ");
myPort.write("#22 P1500 T10 \r ");
myPort.write("#23 P1500 T10 \r ");
}
void robotsit01()
{
myPort.write("#0 P1500 T10 \r ");
myPort.write("#1 P1500 T10 \r ");
myPort.write("#2 P1500 T10 \r ");
myPort.write("#3 P1500 T10 \r ");
myPort.write("#4 P1000 T10 \r ");
myPort.write("#5 P2000 T10 \r ");
myPort.write("#6 P2000 T10 \r ");
myPort.write("#7 P1000 T10 \r ");
myPort.write("#8 P2500 T10 \r ");
myPort.write("#9 P500 T10 \r ");
myPort.write("#10 P1500 T10 \r ");
myPort.write("#11 P1500 T10 \r ");
myPort.write("#12 P500 T10 \r ");
myPort.write("#13 P2500 T10 \r ");
myPort.write("#14 P1500 T10 \r ");
myPort.write("#15 P1500 T10 \r ");
myPort.write("#16 P1500 T10 \r ");
myPort.write("#17 P1500 T10 \r ");
myPort.write("#18 P1500 T10 \r ");
myPort.write("#19 P1500 T10 \r ");
myPort.write("#20 P1900 T10 \r ");
myPort.write("#21 P1900 T10 \r ");
myPort.write("#22 P1500 T10 \r ");
myPort.write("#23 P1500 T10 \r ");
}
void robotsquat01()
{
myPort.write("#0 P1500 T10 \r ");
myPort.write("#1 P1500 T10 \r ");
myPort.write("#2 P500 T10 \r ");
myPort.write("#3 P2500 T10 \r ");
myPort.write("#4 P500 T10 \r ");
myPort.write("#5 P2500 T10 \r ");
myPort.write("#6 P2500 T10 \r ");
myPort.write("#7 P500 T10 \r ");
myPort.write("#8 P2500 T10 \r ");
myPort.write("#9 P500 T10 \r ");
myPort.write("#10 P1500 T10 \r ");
myPort.write("#11 P1500 T10 \r ");
myPort.write("#12 P500 T10 \r ");
myPort.write("#13 P2500 T10 \r ");
myPort.write("#14 P1500 T10 \r ");
myPort.write("#15 P1500 T10 \r ");
myPort.write("#16 P1500 T10 \r ");
myPort.write("#17 P1500 T10 \r ");
myPort.write("#18 P1500 T10 \r ");
myPort.write("#19 P1500 T10 \r ");
myPort.write("#20 P1900 T10 \r ");
myPort.write("#21 P1900 T10 \r ");
myPort.write("#22 P1500 T10 \r ");
myPort.write("#23 P1500 T10 \r ");
}
void robotwalk01()
{
myPort.write("#0 P1500 T1000 \r ");
myPort.write("#1 P1500 T1000 \r ");
myPort.write("#2 P1250 T1000 \r ");
myPort.write("#3 P1250 T1000 \r ");
myPort.write("#4 P1500 T1000 \r ");
myPort.write("#5 P1500 T1000 \r ");
myPort.write("#6 P1500 T1000 \r ");
myPort.write("#7 P1500 T1000 \r ");
myPort.write("#8 P1250 T1000 \r ");
myPort.write("#9 P1250 T1000 \r ");
myPort.write("#10 P1500 T1000 \r ");
myPort.write("#11 P1500 T1000 \r ");
myPort.write("#12 P500 T1000 \r ");
myPort.write("#13 P2500 T1000 \r ");
myPort.write("#14 P1500 T1000 \r ");
myPort.write("#15 P1500 T1000 \r ");
myPort.write("#16 P1500 T1000 \r ");
myPort.write("#17 P1500 T1000 \r ");
myPort.write("#18 P1500 T1000 \r ");
myPort.write("#19 P1500 T1000 \r ");
myPort.write("#20 P1900 T1000 \r ");
myPort.write("#21 P1900 T1000 \r ");
myPort.write("#22 P1500 T1000 \r ");
myPort.write("#23 P1500 T1000 \r ");
}
void robotwalk02()
{
myPort.write("#0 P1500 T1000 \r ");
myPort.write("#1 P1500 T1000 \r ");
myPort.write("#2 P1750 T1000 \r ");
myPort.write("#3 P1750 T1000 \r ");
myPort.write("#4 P1500 T1000 \r ");
myPort.write("#5 P1500 T1000 \r ");
myPort.write("#6 P1500 T1000 \r ");
myPort.write("#7 P1500 T1000 \r ");
myPort.write("#8 P1750 T1000 \r ");
myPort.write("#9 P1750 T1000 \r ");
myPort.write("#10 P1500 T1000 \r ");
myPort.write("#11 P1500 T1000 \r ");
myPort.write("#12 P500 T1000 \r ");
myPort.write("#13 P2500 T1000 \r ");
myPort.write("#14 P1500 T1000 \r ");
myPort.write("#15 P1500 T1000 \r ");
myPort.write("#16 P1500 T1000 \r ");
myPort.write("#17 P1500 T1000 \r ");
myPort.write("#18 P1500 T1000 \r ");
myPort.write("#19 P1500 T1000 \r ");
myPort.write("#20 P1900 T1000 \r ");
myPort.write("#21 P1900 T1000 \r ");
myPort.write("#22 P1500 T1000 \r ");
myPort.write("#23 P1500 T1000 \r ");
}
public void controlEvent(ControlEvent theEvent)
{
n = 0;
}
public void Stand(int theValue)
{
robotstand01();
}
public void Sit(int theValue)
{
robotsit01();
}
public void Squat(int theValue)
{
robotsquat01();
}
public void Walk(int theValue)
{
robotwalk01();
delay(1000);
robotwalk02();
delay(1000);
redraw();
}
[/code]
1