Go Down

Topic: Serial Controlling L.E.D's (Read 1 time) previous topic - next topic

XxAmericanEaglexX

Hey everybody

I received my Arduino not too long ago, and kind of went head first into it. I'm an intermediate programmer in VB and a few other languages, but the Arduino coding is new to me.

Basically, what I'm trying to do is control multiple L.E.D's Brightness on the Arduino using Visual Basic 2008. In other words, a RGB setup. I have already made my form and it uses a Colour Dialog to let you select any colour you want, 3 labels then display the Red value, Blue value and Green value. Can someone help me with the code for the Arduino? What would I send using the Serial Port tool in Visual Basics? I'm a complete noob right now, so any help would be appreciated  :)

If anyone is wondering, I am using the PWM ports 9, 10, and 11, and the Arduino Duemilanove board.

zoomkat

Quote
Can someone help me with the code for the Arduino?


Sure, use the search function at the top of this page and search for things like RGB and LED to see code that has been already been posted. Just look at the most recent postings and you should find a day's worth of reading.
Google forum search: Use Google Search box in upper right side of this page.
Why I like my 2005 Rio Yellow Honda S2000  https://www.youtube.com/watch?v=pWjMvrkUqX0

MikMo

#2
Nov 13, 2010, 11:11 pm Last Edit: Nov 13, 2010, 11:11 pm by MikMo Reason: 1
try here:

http://todbot.com/blog/spookyarduino/

Look for the serial RGB project(s)

Should give you a good starting point.

thoed

http://www.earthshineelectronics.com/files/ASKManualRev4.pdf

Page 58.

Great tutorial that explains the code and the hardware setup.   I've used it many a time, got a copy on each PC. :)

m.ryandesign

I recently used this code to set the color of rgb bulbs over serial.

Sorry for the lack of comments... the way I use it is to send 4 values seperated by spaces, then an ending character. You should call my function checkSerial() in your loop()

For example to set the first light, I would send the string "0 255 255 255 e"

This would turn red, green and blue on at once to mix into white.

Code: [Select]

int serialBuffer[4];
int serialIndex = 0;
char buffer[3];
int bufferIndex = 0;
int serialRgbIndex= 0;
int commandLight;
int serialRgb[3];

void checkSerial()
{
while(Serial.available() > 0)
 {
   int ascii = Serial.read();
   switch(ascii)
   {
   case 32:
     bufferIndex = 0;
     if(serialRgbIndex == 0)
     {
       commandLight = atoi(buffer);  
       serialRgbIndex ++;
     }
     else
     {
       serialRgb[serialRgbIndex - 1] = atoi(buffer);
       serialRgbIndex ++;
     }
     bufferIndex = 0;
     break;

   case 101:
     bufferIndex = 0;
     serialRgbIndex = 0;
     setLight(commandLight, serialRgb);
     break;

   default:
     buffer[bufferIndex] = ascii;
     bufferIndex ++;
     break;
   }
 }
}


Go Up