🛠️ Dive into our collection of DIY Kits, 🔊 Audio Amplifiers, Digital Scoreboards, FM transmitters, and more!
🎶 Explore endless possibilities at our new store.


Arduino Sketch- RGB multicolor lamp

Link to this gist: https://gist.github.com/buildcircuit/3939423

/*
Multicolor Lamp (works with Amarino and the MultiColorLamp Android app)
- based on the Amarino Multicolor Lamp tutorial
- receives custom events from Amarino changing color accordingly
First author: Bonifaz Kaufmann - December 2009
The source works for Amarino Evaluation shield from BuildCircuit.com
*/
#include <MeetAndroid.h>
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(13, 12, 10, 9, 8, 7);
// declare MeetAndroid so that you can call functions with it
MeetAndroid meetAndroid;
// we need 3 PWM pins to control the leds
int redLed = 3;
int blueLed = 5;
int greenLed = 6;
void setup()
{
lcd.begin(16, 2);
// initialize the serial communications:
Serial.begin(9600);
lcd.write("RGB Lamp");
// register callback functions, which will be called when an associated event occurs.
meetAndroid.registerFunction(red, 'r');
meetAndroid.registerFunction(green, 'g');
meetAndroid.registerFunction(blue, 'b');
// set all color leds as output pins
pinMode(redLed, OUTPUT);
pinMode(greenLed, OUTPUT);
pinMode(blueLed, OUTPUT);
// just set all leds to high so that we see they are working well
digitalWrite(redLed, HIGH);
digitalWrite(greenLed,HIGH);
digitalWrite(blueLed, HIGH);
}
void loop()
{
meetAndroid.receive(); // you need to keep this in your loop() to receive events
}
/*
* Whenever the multicolor lamp app changes the red value
* this function will be called
*/
void red(byte flag, byte numOfValues)
{
analogWrite(redLed, meetAndroid.getInt());
}
/*
* Whenever the multicolor lamp app changes the green value
* this function will be called
*/
void green(byte flag, byte numOfValues)
{
analogWrite(greenLed, meetAndroid.getInt());
}
/*
* Whenever the multicolor lamp app changes the blue value
* this function will be called
*/
void blue(byte flag, byte numOfValues)
{
analogWrite(blueLed, meetAndroid.getInt());
}


🛠️ Dive into our collection of DIY Kits, 🔊 Audio Amplifiers, Digital Scoreboards, FM transmitters, and more!
🎶 Explore endless possibilities at our new store.


Leave a Reply

Your email address will not be published. Required fields are marked *