Advertisement
Guest User

Untitled

a guest
May 28th, 2015
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. /*
  2. Multicolor Lamp (works with Amarino and the MultiColorLamp Android app)
  3.  
  4. - based on the Amarino Multicolor Lamp tutorial
  5. - receives custom events from Amarino changing color accordingly
  6.  
  7. author: Bonifaz Kaufmann - December 2009
  8. */
  9.  
  10. #include <MeetAndroid.h>
  11.  
  12. // declare MeetAndroid so that you can call functions with it
  13. MeetAndroid meetAndroid;
  14.  
  15. // we need 3 PWM pins to control the leds
  16. int redLed = 3; // Controls RED color at pin 3
  17. int greenLed = 5; // Control GREEN color at pin 5
  18. int blueLed = 6; // Controls BLUE color at pin 6
  19.  
  20. void setup()
  21. {
  22. // use the baud rate your bluetooth module is configured to
  23. // not all baud rates are working well, i.e. ATMEGA168 works best with 57600
  24. Serial.begin(9600);
  25.  
  26. // register callback functions, which will be called when an associated event occurs.
  27. meetAndroid.registerFunction(red, 'r');
  28. meetAndroid.registerFunction(green, 'g');
  29. meetAndroid.registerFunction(blue, 'b');
  30.  
  31. // set all color leds as output pins
  32. pinMode(redLed, OUTPUT);
  33. pinMode(greenLed, OUTPUT);
  34. pinMode(blueLed, OUTPUT);
  35.  
  36. // just set all leds to high so that we see they are working well
  37. digitalWrite(redLed, HIGH);
  38. digitalWrite(greenLed,HIGH);
  39. digitalWrite(blueLed, HIGH);
  40.  
  41. }
  42.  
  43. void loop()
  44. {
  45. meetAndroid.receive(); // you need to keep this in your loop() to receive events
  46.  
  47. }
  48.  
  49. /*
  50. * Whenever the multicolor lamp app changes the red value
  51. * this function will be called
  52. */
  53. void red(byte flag, byte numOfValues)
  54. {
  55. analogWrite(redLed, meetAndroid.getInt());
  56. }
  57.  
  58. /*
  59. * Whenever the multicolor lamp app changes the green value
  60. * this function will be called
  61. */
  62. void green(byte flag, byte numOfValues)
  63. {
  64. analogWrite(greenLed, meetAndroid.getInt());
  65. }
  66.  
  67. /*
  68. * Whenever the multicolor lamp app changes the blue value
  69. * this function will be called
  70. */
  71. void blue(byte flag, byte numOfValues)
  72. {
  73. analogWrite(blueLed, meetAndroid.getInt());
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement