Skip to content

Instantly share code, notes, and snippets.

@buildcircuit
Created October 23, 2012 15:25
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save buildcircuit/3939423 to your computer and use it in GitHub Desktop.
RGB based Multicolor Lamp using Amarino Evaluation Shield
/*
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());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment