document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #include <SoftwareSerial.h>
  2. #include <Adafruit_NeoPixel.h>
  3. #ifdef __AVR__
  4. #include <avr/power.h>
  5. #endif
  6. #define NUMLED 3
  7. #define DATAPIN 5
  8.  
  9. int buzzer= 9;
  10. int button= 2;
  11. char c;
  12. bool notifica=true;
  13. SoftwareSerial bluetooth (6, 7); //TX and RX pins
  14. Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMLED, DATAPIN, NEO_GRB + NEO_KHZ800);
  15.  
  16. void setup() {
  17. pinMode(buzzer,OUTPUT);
  18. pinMode(5,OUTPUT);
  19. pinMode(button,INPUT_PULLUP);
  20.  
  21.  
  22. bluetooth.begin(38400);
  23. delay(100);
  24.  
  25. pixels.begin();
  26. delay(100);
  27.  
  28. attachInterrupt(digitalPinToInterrupt(2), buttonpressed, FALLING); //I chose FALLING because it works when the pin goes from high to low
  29. }
  30.  
  31. void loop() {
  32. if(bluetooth.available() > 0){ //slave (reader) search the main device (master as sender)
  33. c = bluetooth.read(); //slave reads data from master
  34. if(c=='1'){
  35. if (notifica){
  36.  
  37. analogWrite(buzzer,200);
  38. pixels.setPixelColor(0, pixels.Color(0, 0, 150));
  39. pixels.setPixelColor(1, pixels.Color(0, 0, 150));
  40. pixels.setPixelColor(2, pixels.Color(0, 0, 150));
  41. pixels.show();
  42. delay(2000);
  43. analogWrite(buzzer,0);
  44. pixels.setPixelColor(0, pixels.Color(0, 0, 0));
  45. pixels.setPixelColor(1, pixels.Color(0, 0, 0));
  46. pixels.setPixelColor(2, pixels.Color(0, 0, 0));
  47. pixels.show();
  48. }
  49. }
  50. }
  51. }
  52. void buttonpressed() { //button as interrupt allows the user to have notification or not
  53. if (notifica==true) { //condition 1
  54. notifica=false;
  55. }
  56. else {
  57. notifica=true; //condition 2
  58. }
  59. }
');