We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi,
My code below almost works. I have a text entry field and want the option to either enter the number manually or use keys 'm' & 'n' to scroll up or down through the numbers. The scrolling works and updates the text field, but when I try entering a number the text field only accepts the first number and not a String of numbers.
Any ideas?
import controlP5.*;
ControlP5 cp5;
int x = 0;
void setup() {
size(400,200);
PFont font = createFont("arial",10);
cp5 = new ControlP5(this);
cp5.addTextfield("Path")
.setPosition(100,100)
.setSize(100,15)
.setFont(font)
.setColor(255)
.setAutoClear(false)
.setText(Integer.toString(x))
.setValue(0)
;
textFont(font);
}
void draw() {
background(0);
fill(255);
}
void keyPressed() {
if (key=='q' && x != 0) x--;
if (key=='a' && x != 199) x++;
cp5.get(Textfield.class,"Path").setText(Integer.toString(x));
}
void controlEvent(ControlEvent theEvent) {
if(theEvent.isAssignableFrom(Textfield.class)) x = Integer.parseInt(cp5.get(Textfield.class,"Path").getText());
}
Answers
http://www.sojamo.de/libraries/controlP5/reference/controlP5/Textfield.html#setInputFilter(int)
http://www.sojamo.de/libraries/controlP5/reference/controlP5/Textfield.InputFilter.html#INTEGER
+
or function str():"" + x
orx + ""
orstr(x)
(int)
is enough!Thanks GoToLoop,
With your advice I got a little further. The looping was a silly error and you're right about the verbosity - this comes from looking at Java forums for solutions.
The code I have now works and it's good enough for my purposes, but for the setInputFilter() I just couldn't workout what I should write in order to implement it as I'm not that used to the Java documentation. When the focus is on the text field and I use 'q' & 'a' to navigate the text appears in the box, but since the 'displayPath' doesn't pick up the characters it doesn't cause an error. It's just a bit ugly.
Sorry about that 1! Seems like Textfield.InputFilter.INTEGER is for internal use. b-(
Nevertheless, found out that ControlP5.INTEGER works instead! *-:)
Now things got easier as the Textfield only accepts number characters now! \m/
hi Setup, hi gotoloop, Can you help solve my problem ??
I want to send the value of the text field to set the pace a servo, but I do not know how to send these values, and I marked with a question mark on the sketch because I do not know. please help me, help you all would be greatly appreciated. The following is a sketch of processing.
This is arduino sketch to receive the value to be sent from the processing
please help me to finish this project, thanks.