Arduino Projects: Difference between revisions

(added code)
Line 440:
 
= Bluetooth Controlled RGB LED Strip =
Source: [[https://www.arduino.cc/en/Tutorial/ReadASCIIString arduino.cc]], [[https://play.google.com/store/apps/details?id=com.embarcadero.AndroidunoBt&hl=en play.google.com]]
 
<pre style="width: 75%; height: 10pc; overflow-y: scroll;">/*
Reading a serial ASCII-encoded string.
 
This sketch demonstrates the Serial parseInt() function.
It looks for an ASCII string of comma-separated values.
It parses them into ints, and uses those to fade an RGB LED.
 
Circuit: Common-Cathode RGB LED wired like so:
* Red anode: digital pin 3
* Green anode: digital pin 5
* Blue anode: digital pin 6
*/
 
// pins for the LEDs:
const int redPin = 3;
const int greenPin = 5;
const int bluePin = 6;
void setup() {
// initialize serial:
Serial.begin(9600);
// make the pins outputs:
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}
 
void loop() {
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();
 
// 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);"
red = constrain(red, 0, 255);
green = constrain(green, 0, 255);
blue = constrain(blue, 0, 255);
 
// fade the red, green, and blue legs of the LED:
analogWrite(redPin, red);
analogWrite(greenPin, green);
analogWrite(bluePin, blue);
 
// print the three numbers in one string as hexadecimal:
Serial.print(red, HEX);
Serial.print(green, HEX);
Serial.println(blue, HEX);
}
}
}
</pre>
 
= IR Controlled RGB LED Strip =
Source: [[http://arduino-cool.blogspot.in/2012/09/arduino-rgb-led-managed-by-remote.html arduino-cool.blogspot.in]]