Hi,
I’m new in Processing.
How can I send only 1 data from Processing to Python every time I use mousePressed == true, the data changes in void draw().
I tried and every time I press the mouse, the data that was sent to Python was a string of data sticks together…
For example, the data i would be: 1, then 2, then 3…, it changes in void draw() loop; then I press the mouse when the time at i=5, Python received: 12345.
Please give me some suggestions/ideas to handle this, which command I should use to delete the previous datas, I only need the last data when I press the mouse.
Thank you all!
Don’t use the mousePressed
boolean. Instead, use the mousepressed()
function.
The boolean is true if the mouse is pressed, which could be for several iterations of the draw() loop per click.
But the function only happens once per click, which sounds like exactly what you want.
void setup(){...}
void draw(){...}
void mousepressed(){
send_data(i++);
}
Thank you very much @TfGuy44.
I changed “i” to the global variable and added mousePressed() function, “i” still changed in draw() loop and then it works.
Thank you again!!!
One more “newbie” question, how can I use a variable in draw() loop in a diffrent function, if that variable doesn’t declare as a global variable?
Thank you!
You don’t. That’s the big difference between global variables and local ones. Only global variables can be accessed in all your sketch’s functions.