We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Serial value as a variable
Page Index Toggle Pages: 1
Serial value as a variable (Read 467 times)
Serial value as a variable
Nov 1st, 2009, 6:14pm
 
Hello,

My serial input is a value between 0-1023, being refreshed every 500ms.
I'm basically attempting to replace the "mouseY" variable in the "Hue" example with serial input, divided by 5 to get it within an acceptable range. But I can't figure out how to get the function to call and store the serial value more than once. Maybe this isn't happening at all!

Any suggestions? I understand that the draw() should loop, so why doesn't the ser = myPort.read() continue to get reset to the current value?


Code:
void draw() {
{
 }
 int j = 0;
 for (int i=0; i<=(width-barWidth); i+=barWidth) {  
   if ((mouseX > i) && (mouseX < i+barWidth)) {
     ser = myPort.read();
       hue[j] = ser/5;
     //hue[j] = mouseY;    
   }
   fill(hue[j], height/1.2, height/1.2);
   rect(i, 0, barWidth, height);  
   j++;
  loop();
 }


Re: Serial value as a variable
Reply #1 - Nov 1st, 2009, 8:34pm
 
Assuming "ser" is declared elsewhere...
I think "hue" is a variable name owned by Processing, so you might solve your issue by renaming that array...You can also println(ser) to see what you're dealing with.
And loop() is used only to turn looping back on in case it has been disabled with noLoop() -- draw() loops by default.
Page Index Toggle Pages: 1