Android, USB control RGB LED, copy and test


 

 

http://wp.me/ph3BR-1mo

 

RGB_LED, current limit resistor, 1k ohm x 3

RGB_LED

RGB_test_schematic nEO_IMG_RGB_test_rig

google play, install USB arduino control RGB

burn code to arduino

OTG cable, connect arduino and android phone

 

 

h_t_tp://youtu.be/s75g86kn0-U

http://youtu.be/s75g86kn0-U

 


//pins for the LEDs:
const int redPin = 3;
const int greenPin = 5;
const int bluePin = 6;

const int redPin2 = 9;
const int greenPin2 = 10;
const int bluePin2 = 11;

#define REDPIN 3
#define GREENPIN 5
#define BLUEPIN 6

#define FADESPEED 5

void setup() {
// initialize serial:
Serial.begin(9600);

// make the pins outputs:
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);

pinMode(redPin2, OUTPUT);
pinMode(greenPin2, OUTPUT);
pinMode(bluePin2, OUTPUT);

Serial.print("Arduino control RGB LEDs Connected OK ( Sent From Arduinno Board )");
Serial.print('\n');
}

void loop() {

// if there's any serial available, read it:
while (Serial.available() > 0) {

// look for the next valid integer in the incoming serial stream:
int red = Serial.parseInt();
// do it again:
int green = Serial.parseInt();
// do it again:
int blue = Serial.parseInt();

int red2 = Serial.parseInt();
// do it again:
int green2 = Serial.parseInt();
// do it again:
int blue2 = Serial.parseInt();

// look for the newline. That's the end of your
// sentence:
if (Serial.read() == '\n') {

// constrain the values to 0 - 255 and invert
// if you're using a common-cathode LED, just use "constrain(color, 0, 255);"

// This is for COMMON ANODE
//red = 255 - constrain(red, 0, 255);
//green = 255 - constrain(green, 0, 255);
//blue = 255 - constrain(blue, 0, 255);

red = constrain(red, 0, 255);
green = constrain(green, 0, 255);
blue = constrain(blue, 0, 255);

red2 = constrain(red2, 0, 255);
green2 = constrain(green2, 0, 255);
blue2 = constrain(blue2, 0, 255);

// fade the red, green, and blue legs of the LED:
analogWrite(redPin, red);
analogWrite(greenPin, green);
analogWrite(bluePin, blue);

analogWrite(redPin2, red2);
analogWrite(greenPin2, green2);
analogWrite(bluePin2, blue2);

// print the three numbers in one string as hexadecimal:
Serial.print("Data Response : ");
Serial.print(red, HEX);
Serial.print(green, HEX);
Serial.println(blue, HEX);
}
}

}

REF

copy from, http://microcontrollerkits.blogspot.tw/2013/06/arduino-control-rgb-led-via-serial-port.html

http://wp.me/ph3BR-ob

廣告

發表迴響

在下方填入你的資料或按右方圖示以社群網站登入:

WordPress.com Logo

您的留言將使用 WordPress.com 帳號。 登出 / 變更 )

Twitter picture

您的留言將使用 Twitter 帳號。 登出 / 變更 )

Facebook照片

您的留言將使用 Facebook 帳號。 登出 / 變更 )

Google+ photo

您的留言將使用 Google+ 帳號。 登出 / 變更 )

連結到 %s