We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I control manages speed dc motor , I want to show the speed that is read by arduino , but the speed sent by arduino can only appear on the monitor serial processing , all I want is a display in the window " run" . this is processing code :
`import controlP5.*;
import processing.serial.*;
ControlP5 cP5a;
ControlP5 cP5b;
ControlP5 cP5c;
ControlP5 cP5d;
ControlP5 cP5e;
ControlP5 cP5f;
ControlP5 cP5g;
ControlP5 cP5h;
Serial arduino;
String val;
void setup()
{
size(785, 520);
println(Serial.list());
arduino = new Serial(this, Serial.list()[0], 9600);
cP5a = new ControlP5(this);
cP5a.addSlider("ATUR_KECEPATAN_MOTOR_DC", 0, 255, 0, 30, 155, 350, 50);
cP5b = new ControlP5(this);
cP5b.addButton("FORWARD",1,30,220,100,40);
cP5c = new ControlP5(this);
cP5c.addButton("REVERSE",0,280,220,100,40);
cP5d = new ControlP5(this);
cP5d.addButton("BUKA_GERBANG",1,30,300,100,40);
cP5e = new ControlP5(this);
cP5e.addButton("TUTUP_GERBANG",1,30,355,100,40);
cP5f = new ControlP5(this);
cP5f.addSlider("SUDUT_SERVO", 0, 180, 0, 30, 435, 350, 50);
cP5g = new ControlP5(this);
cP5g.addButton("MASTER_ON",1,30,80,100,35);
cP5h = new ControlP5(this);
cP5h.addButton("MASTER_OFF",0,160,80,100,35);
}
void draw()
{
background(#614DED);
textSize(20);
fill(#F5ED00);
text("PENGENDALI MOTOR DC MOTOR STEPPER DAN MOTOR SERVO", 100, 30);
textSize(18);
text("KECEPATAN MOTOR DC :", 500, 140);
textSize(18);
text("FIANSYAH AFANDI RAKHMAN, TEKNIK ELEKTRO, UNIVERSITAS SILIWANGI TASIKMALAYA", 10,60);
textSize(15);
text("A. MOTOR DC", 15,140);
textSize(15);
text("B. MOTOR STEPPER", 15,285);
textSize(15);
text("C. MOTOR SERVO", 15,420);
textSize(13);
fill(#020108);
text("created by: Fiansyah Afandi Rakhman", 545, 500);
text("107002025/elektro2010", 617, 515);
if (arduino.available() >0){
val=arduino.readStringUntil('\n');}
println(val);
}
void controlEvent(ControlEvent theEvent) {
if(theEvent.isController()) {
print("control event from : "+theEvent.controller().name());
println(", value : "+theEvent.controller().value());
if(theEvent.controller().name()=="ATUR_KECEPATAN_MOTOR_DC") {
int val1 = int(theEvent.getController().getValue());
arduino.write("a" + val1);
}
if(theEvent.controller().name()=="FORWARD") {
int val2 = int(theEvent.getController().getValue());
arduino.write("b" + val2 );
}
if(theEvent.controller().name()=="REVERSE") {
int val3 = int(theEvent.getController().getValue());
arduino.write("c" + val3);
}
if(theEvent.controller().name()=="BUKA_GERBANG") {
int val4 = int(theEvent.getController().getValue());
arduino.write("d" + val4 );
}
if(theEvent.controller().name()=="TUTUP_GERBANG") {
int val5 = int(theEvent.getController().getValue());
arduino.write("e" + val5 );
}
if(theEvent.controller().name()=="SUDUT_SERVO") {
int val6 = int(theEvent.getController().getValue());
arduino.write("f" + val6);
}
if(theEvent.controller().name()=="MASTER_ON") {
int val7 = int(theEvent.getController().getValue());
arduino.write("g" + val7);
}
if(theEvent.controller().name()=="MASTER_OFF") {
int val8 = int(theEvent.getController().getValue());
arduino.write("h" + val8);
}
}
}`
in this section :
if (arduino.available() >0){
val=arduino.readStringUntil('\n');}
println(val);
when i added into :
if (arduino.available() >0){
val=arduino.readStringUntil('\n');}
println(val);
textSize(18);
text(val, 500, 180);
there is an error, and there is written "could'nt run the sketch" and the problem is this section :
text(val, 500, 180)
help me to solve this problem , how to correct sketch writing if you want to display a string on the run window . Thank you , any help would be greatly appreciated
Answers
text(trim(val), 500, 180);
or
text(trim(str(val)), 500, 180);
??
Chrisir thank you , I really appreciate your help , and I am very happy . My problem is solved , but new problems arise , I do not know how to change the position of the variable " val " to be in the position I want, this is my code
I want to ask is how to adjust the position of " val " to be positioned in the position I wanted.
text(val, width/2, height/2);
thankyou...
so what values do you want?
look at map() please in the reference
This discussion continues here