Go Down

Topic: Serial.help() (Read 278 times) previous topic - next topic

ash901226

hay guys,
i know this question have been ask as many time as posible yet here i am again.
i got this fucntion that i would like to be able to control thru serial,
Code: [Select]

void SetRGB(int address,int red,int green,int blue)
{
  digitalWrite(slaveSelectPin,LOW);
  SPI.transfer(Red[address]);
  SPI.transfer(red);
  SPI.transfer(Green[address]);
  SPI.transfer(green);
  SPI.transfer(Blue[address]);
  SPI.transfer(blue);
  digitalWrite(slaveSelectPin,HIGH);
}


what i want to know is how can i get info from the serial for adress,red value(0-255),green(0-255), and blue value(0-255) in that order if i can, but if its easier for not to be sequential its ok ....

Osgeld

the easiest is to send 3 bytes

http://arduino.cc/en/Serial/ReadBytes
http://arduino.cc/forum/index.php?action=unread;boards=2,3,4,5,67,6,7,8,9,10,11,66,12,13,15,14,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,86,87,89,1;ALL

ash901226

how to use Serial.readBytes() there is no example that i could posibbly think how to use it

ash901226

after trying to understand what it does mean by
Quote

Serial.readBytes() reads characters from the serial port into a buffer. The function terminates if the determined length has been read, or it times out


i realize what i mean is something like this?
Code: [Select]

address=Serial.readBytes(byte,2);
red=Serial.readBytes(byte,3);
green=Serial.readBytes(byte,3);
blue=Serial.readBytes(byte,3);


am i rite to assume this?

Osgeld

#4
Jan 16, 2013, 05:28 am Last Edit: Jan 16, 2013, 05:31 am by Osgeld Reason: 1
sort of

you should plop in a SerialAvailable to see if there is anything in the buffer as well, for example (just ignoring the address for now)

Code: [Select]
char data[3];

void setup()
{
 Serial.begin(9600);
}

void loop()
{
 if (Serial.available())
 {
   Serial.readBytes(data, 3);  
   digitalWrite(slaveSelectPin,LOW);
   SPI.transfer(data[0]); // red
   SPI.transfer(data[1]); // green
   SPI.transfer(data[2]); // blue
   digitalWrite(slaveSelectPin,HIGH);
 }
}


each byte is an 8 bit value, repersenting 0-255
http://arduino.cc/forum/index.php?action=unread;boards=2,3,4,5,67,6,7,8,9,10,11,66,12,13,15,14,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,86,87,89,1;ALL

ash901226

what if i want the address to have a value of 0 to 40 and the value of red,green ,and blue is between 0 to 4095

PaulS

Quote
what if i want the address to have a value of 0 to 40 and the value of red,green ,and blue is between 0 to 4095

What if you actually try something, show some code, show some serial output, and describe what happened?

What is sending the serial data? In what format?

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy