Go Down

Topic: sending multiple values in port.write in processing (Read 4 times) previous topic - next topic

sataman

#10
Dec 08, 2012, 06:56 pm Last Edit: Dec 08, 2012, 06:58 pm by sataman Reason: 1
i also facing the same problem to let my LCD display the data

the part of the processing is

 port.write('R');
 port.write(RED);

 port.write('G');
 port.write(GREEN);

  port.write('B');
 port.write(BLUE);

arduino is

// call the returned value from GetFromSerial() function
 switch(GetFromSerial())
 {
 case 'R':
 
   
   lcd.setCursor(1,0);
   lcd.print("R :"+ GetFromSerial());




   break;
case 'G'

....
....
break;
...
case 'B'
...
break

 }
}

// read the serial port
int GetFromSerial()
{
 while (Serial.available()<=0) {
 }
 return Serial.read();
}
the proble for me is the LCD did not display in proper ...if i remove the GetFromSerial for  lcd.print("R :"+ GetFromSerial()); not do not have any problem, can i know any solution??
i need my LCD to display the RED,GREEN,BLUE value from processing
thank you

PaulS

Code: [Select]
    lcd.print("R :"+ GetFromSerial());
Suppose that GetFromSerial() returns the value 12. What, exactly, do you expect adding 12 to "R :" to result in? + is NOT a concatenation operator. It is an addition operator.

sataman

#12
Dec 08, 2012, 07:07 pm Last Edit: Dec 08, 2012, 07:19 pm by sataman Reason: 1
No .i put + is just to let lcd continue print the variable (RED) i want my LCD to display the data from the Processing ..'which is RED,GREEN ,and BLUE...i have no idea how LCD and display 3 in same time?

port.write('R');
 port.write(RED);

 port.write('G');
 port.write(GREEN);

 port.write('B');
 port.write(BLUE);

the RED is an interger value

if work perfect in
case 'R':
   analogWrite(9, GetFromSerial());//arduino pin 9 for LED
   break;
the intensity of the light will change according to the RED value
but i do not know why it can not work in lcd to display out the RED value
i till keep give me the random char

PaulS

Quote
but i do not know why it can not work in lcd to display out the RED value

It can. You MUST use TWO statements to print the "R :" part and the value. You can NOT use the addition operator HOPING that somehow it will magically be interpreted as a concatenation operator, just because that is what you want.

sataman


Quote
but i do not know why it can not work in lcd to display out the RED value

It can. You MUST use TWO statements to print the "R :" part and the value. You can NOT use the addition operator HOPING that somehow it will magically be interpreted as a concatenation operator, just because that is what you want.


thank you very much i have change the code to

    lcd.setCursor(1,0);
    lcd.print("R :");
    lcd.print(GetFromSerial());
it work !! :)

Go Up