Hello my dear friends,
I am adding button for open the led. I want to write text on the Button. I am adding text but I can’t see this. Text is under the Button. I want to see that. I am sharing codes. I want to text “START” and “STOP” on the Button. Thanks for reading…
import processing.serial.*;
Serial myArduinoPort;
float buttonA_x = 103.8;
int buttonA_y = 35;
int buttonA_width = 120;
int buttonA_height = 85;
int buttonA_colorR = 0x25;
int buttonA_colorG = 0x25;
int buttonA_colorB = 0x25;
float buttonB_x = 103.8;
int buttonB_y = 130;
int buttonB_width = 120;
int buttonB_height = 85;
int buttonB_colorR = 0x25;
int buttonB_colorG = 0x25;
int buttonB_colorB = 0x25;
int defaultColor = 125;
boolean buttonA_clicked = false;
boolean buttonB_clicked = false;
int value = 0;
int valueo = 1;
int d = day(); // Values from 1 - 31
int m = month(); // Values from 1 - 12
int y = year(); // 2003, 2004, 2005, etc.
void setup() {
size(335, 230);
background(125, 125, 125);
//Get serial port for Arduino
String arduinoPort = Serial.list()[0];
println(arduinoPort);
myArduinoPort = new Serial(this, arduinoPort, 9600);
fill(0, 0, 0);
text("LED CONTROL", 119, 20);
fill(0, 0, 0);
text("/", 286, 220);
fill(0, 0, 0);
text("/", 296, 220);
String s = String.valueOf(d);
text(s, 272, 220);
s = String.valueOf(m);
text(s, 290, 220);
s = String.valueOf(y);
text(s, 300, 220);
}
void draw() {
if(buttonA_clicked){
fill(buttonA_colorR, buttonA_colorG, buttonA_colorB);
}else if(buttonB_clicked){
fill(buttonB_colorR, buttonB_colorG, buttonB_colorB);
}
fill(buttonA_colorR, buttonA_colorG, buttonA_colorB);
rect(buttonA_x, buttonA_y, buttonA_width, buttonA_height);
fill(buttonB_colorR, buttonB_colorG, buttonA_colorB);
rect(buttonB_x, buttonB_y, buttonB_width, buttonB_height);
}
/* The mouseClicked() function is called once after a mouse button
* has been pressed and then released.
*/
void mouseClicked(){
// mouseX = x of mouse click position
// mouseY = y of mouse click position
if (mouseX >= buttonA_x && mouseX <= buttonA_x + buttonA_width &&
mouseY >= buttonA_y && mouseY <= buttonA_y + buttonA_height) {
buttonA_clicked = true;
myArduinoPort.write("H");
} else {
buttonA_clicked = false;
}
if (mouseX >= buttonB_x && mouseX <= buttonB_x + buttonB_width &&
mouseY >= buttonB_y && mouseY <= buttonB_y + buttonB_height) {
buttonB_clicked = true;
myArduinoPort.write("L");
} else {
buttonB_clicked = false;
}
}