/* Pillow Alarm
by James Leng 2010.04.05 */
- include <MeetAndroid.h>
// declare MeetAndroid so that you can call functions with it MeetAndroid meetAndroid;
// First RGB LED int ledPin = 13; int redPin = 18; int greenPin = 16; int bluePin = 17;
// Vibration Motors int motorPin = 6;
int i = 0;
void setup() {
// set baud rate of bluetooth module Serial.begin(57600); // register callback functions, which will be called when an associated event occurs. // 'A' is the event flag for turning the motor alarm on // 'B' is the event flag for turning the motor alarm off meetAndroid.registerFunction(alarmOn, 'a'); meetAndroid.registerFunction(alarmOff, 'b'); meetAndroid.registerFunction(weatherSunny, 's'); meetAndroid.registerFunction(weatherCloudy, 'c'); meetAndroid.registerFunction(weatherRainy, 'r'); // set all color leds as output pins pinMode(ledPin, OUTPUT); pinMode(redPin, OUTPUT); pinMode(greenPin, OUTPUT); pinMode(bluePin, OUTPUT); pinMode(motorPin, OUTPUT);
}
void loop() {
meetAndroid.receive(); // you need to keep this in your loop() to receive events
}
void alarmOn(byte flag, byte numOfValues) {
int j = 0; // 3 short bursts of vibration for(j = 0; j < 3; j++) { digitalWrite(ledPin, HIGH); digitalWrite(motorPin, HIGH); delay(1000); digitalWrite(ledPin, LOW); digitalWrite(motorPin, LOW); delay(500); } // 1 long vibration digitalWrite(ledPin, HIGH); delay(5000); digitalWrite(ledPin, LOW); delay(500);
}
void alarmOff(byte flag, byte numOfValues) {
digitalWrite(ledPin, LOW); digitalWrite(motorPin, LOW);
}
void weatherSunny(byte flag, byte numOfValues) {
color(255, 255, 0);
}
void weatherCloudy(byte flag, byte numOfValues) {
color(255, 0, 255);
}
void weatherRainy(byte flag, byte numOfValues) {
color(0, 255, 255);
}
void color (unsigned char red, unsigned char green, unsigned char blue) // the color generating function {
analogWrite(redPin, 255-red); analogWrite(bluePin, 255-blue); analogWrite(greenPin, 255-green);
}