Sunday, June 20, 2010

LED Change Code (Arduino)

LED Change Code (Arduino)
// Simple LED on at various power levels - Serge
char serInString[10]; // array that will hold the bytes of the incoming string
int dataRead = 0;
void setup(){
// Set up pins
Serial.begin(9600); }
void readSerialString(char *strArray) {
int i = 0;
while (Serial.available()) {
strArray[i] = Serial.read();
i++; }
dataRead = i; }
void loop() {
readSerialString(serInString);
if (dataRead>0) {
int ledPin = serInString[0];
int ledBrightness = serInString[1];
if ((ledPin>=9) && (ledPin<=11)) {
char pinChar = '0' + ledPin;
Serial.println("Turning on LED: " + pinChar);
analogWrite(ledPin, ledBrightness); } }
dataRead = 0;
delay(1000); }
Related Posts Plugin for WordPress, Blogger...
Disclaimer: All the information in this blog is just gathered from different sites in the web and placed here and I am not the owner for these content

Popular Projects

Followers

My Blog List

Give Support

Give Support
Encourage me Through Comments & by Following