Pages: [1]   Go Down
Author Topic: Serial.help()  (Read 228 times)
0 Members and 1 Guest are viewing this topic.
Malaysia
Offline Offline
Sr. Member
****
Karma: 7
Posts: 393
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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 ....
Logged

SE USA
Offline Offline
Faraday Member
**
Karma: 40
Posts: 3783
@ssh0le
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

the easiest is to send 3 bytes

http://arduino.cc/en/Serial/ReadBytes
Logged


Malaysia
Offline Offline
Sr. Member
****
Karma: 7
Posts: 393
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Malaysia
Offline Offline
Sr. Member
****
Karma: 7
Posts: 393
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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?
Logged

SE USA
Offline Offline
Faraday Member
**
Karma: 40
Posts: 3783
@ssh0le
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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
« Last Edit: January 15, 2013, 11:31:48 pm by Osgeld » Logged


Malaysia
Offline Offline
Sr. Member
****
Karma: 7
Posts: 393
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 551
Posts: 46204
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Pages: [1]   Go Up
Jump to: