ControlP5 - Button - Using if pressed and if released
in
Contributed Library Questions
•
8 months ago
Hi Everyone,
I am very new to this and hope someone can help.
Im driving an Arduino Tank and require buttons from ControlP5 to perfom an action while pressing the button than stop once released. I can do this function with keyboard but cant get it to work with ControlP5 buttons
Can this be done?
Thanks Bart
I am very new to this and hope someone can help.
Im driving an Arduino Tank and require buttons from ControlP5 to perfom an action while pressing the button than stop once released. I can do this function with keyboard but cant get it to work with ControlP5 buttons
Can this be done?
Thanks Bart
- import processing.serial.*;
import controlP5.*;
ControlP5 cp5;
import cc.arduino.*;
Arduino arduino;
int hornbeeper = 11; // piezo/beeper connected to digital pin 11
PFont fontA;
PFont chalkF;
PFont digital;
PImage chalk;
PImage horn;
PImage horn1;
void setup() {
size(1024, 683);
println(Arduino.list());
arduino = new Arduino(this, Arduino.list()[0], 57600);
cp5 = new ControlP5(this);
chalk = loadImage("Chalk.jpg");
//Load Fonts
fontA = loadFont("Ziggurat-HTF-Black-32.vlw");
chalkF = loadFont("Chalkboard-Bold-48.vlw");
digital = loadFont("AmericanTypewriter-70.vlw");
textFont(fontA, 20);
//background(#FC0808);
//fill(150); //Text colour
smooth();
cp5.addButton("Horn")
.setPosition(625, 55)
.setImages(loadImage("Horn.png"), loadImage("Horn.png"), loadImage("Horn1.png"))
.updateSize()
.activateBy(ControlP5.PRESSED)
;
}
void draw() {
background(chalk); // Set background to dark gray
fill(#363639, 126);
noStroke();
rect(50, 50,350,600);
rect(425, 50, 550,200);
rect(425, 350, 550,300);
//strokeWeight(1);
fill(250);
stroke(#FFFFFF);
line(175, 90, 275, 90); // underline
line(175, 540, 275, 540); // underline
//HEADINGS
textAlign(CENTER);
textFont(chalkF, 25);
text("Sensors", 225, 85);
text("Rules", 225, 535);
textFont(chalkF,18);
text("TEMPRETUERE", 225, 185);
text("HUMIDITY", 225, 285);
text("LIGHT", 225, 385);
// Rules
textFont(chalkF,13);
text("L/SENSITIVE", 100, 635);
text("SPEED", 225, 635);
text("SERVO1", 475, 635);
text("SERVO2", 550, 635);
// Rule Settings
//text(lightsensitivity, 100, 600);
//text(SPEED, 225, 600);
// Icon Headings
text("LIGHTS", 475, 160);
text("SENSOR", 575, 160);
text("HORN", 675, 160);
text("BATTERY", 775, 160);
//Sesnsor Readings
textAlign(CENTER);
textFont(digital,30);
text("25.5C", 225, 155);
text("40%", 225, 255);
text("125", 225, 355);
}
void keyPressed(){
}
void keyReleased(){
}
public void controlEvent(ControlEvent theEvent) {
println(theEvent.getController().getName());
}
// function buttonA will receive changes from
// controller with name Horn
public void Horn(int theValue) {
//hornval = 1;
arduino.analogWrite(hornbeeper, 950);
}
1