Instantly share code, notes, and snippets.

Embed
What would you like to do?
Android-Arduino Lamp with Bluetooth and Infrared
#include <MeetAndroid.h>
#include <IRremote.h>
MeetAndroid meetAndroid;
int redLed = 9;
const int irReceiverPin = 2;
const int ledPin = 3;
IRrecv irrecv(irReceiverPin); //create an IRrecv object
decode_results decodedSignal; //stores results from IR sensor
void setup() {
Serial.begin(9600); //Start serial interface (for debugging)
meetAndroid.registerFunction(red,'o');
pinMode(redLed,OUTPUT);
analogWrite(redLed,0);
pinMode(ledPin, OUTPUT);
irrecv.enableIRIn(); // Start the receiver object
}
boolean lightState = false; //keep track of whether the LED is on
unsigned long last = millis(); //remember when we last received an IRmessage
void loop(){
meetAndroid.receive();
if (irrecv.decode(&decodedSignal) == true) //this is true if a message has been received
{
if (millis() - last > 250) { //has it been 1/4 sec since last message
lightState = !lightState; //toggle the LED
digitalWrite(ledPin, lightState);
analogWrite(redLed,0);
}
last = millis();
irrecv.resume(); // watch out for another message
}
}
void red(byte flag, byte numOfValues)
{
analogWrite(redLed, meetAndroid.getInt());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment