Advertisement
pleasedontcode

Bluetooth Automation rev_01

Mar 27th, 2024
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: Bluetooth Automation
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2024-03-27 13:04:04
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Collegare il Bluetooth al display che permetta di */
  21.     /* vedere l’ora con il sensore clook, poi il */
  22.     /* Bluetooth verrà collegato al DFPlayer Mini che poi */
  23.     /* verrà collegato allo speaker per far uscire il */
  24.     /* suono, il Bluetooth verrà collegato anche alla */
  25.     /* striscia led */
  26. /****** END SYSTEM REQUIREMENTS *****/
  27.  
  28. /****** DEFINITION OF LIBRARIES *****/
  29. #include <SoftwareSerial.h>
  30.  
  31. /****** FUNCTION PROTOTYPES *****/
  32. void setup(void);
  33. void loop(void);
  34.  
  35. /***** DEFINITION OF Software Serial *****/
  36. const uint8_t Bluetooth_HC05_mySerial_PIN_SERIAL_TX_A0 = A0;
  37. const uint8_t Bluetooth_HC05_mySerial_PIN_SERIAL_RX_A1 = A1;
  38. SoftwareSerial Bluetooth_HC05_mySerial(Bluetooth_HC05_mySerial_PIN_SERIAL_RX_A1, Bluetooth_HC05_mySerial_PIN_SERIAL_TX_A0);
  39.  
  40. // Define pin numbers for clock sensor, speaker, and LED strip
  41. const int clockSensorPin = 2;
  42. const int speakerPin = 3;
  43. const int ledStripPin = 4;
  44.  
  45. void setup(void)
  46. {
  47.     // Initialize Bluetooth communication
  48.     Bluetooth_HC05_mySerial.begin(9600);
  49.  
  50.     // Set pin modes for other components
  51.     pinMode(clockSensorPin, INPUT);
  52.     pinMode(speakerPin, OUTPUT);
  53.     pinMode(ledStripPin, OUTPUT);
  54. }
  55.  
  56. void loop(void)
  57. {
  58.     // Read the current time from the clock sensor
  59.     int currentTime = digitalRead(clockSensorPin);
  60.  
  61.     // Send the current time to the Bluetooth display
  62.     Bluetooth_HC05_mySerial.println(currentTime);
  63.  
  64.     // Play a sound using the speaker
  65.     tone(speakerPin, 1000, 1000);
  66.  
  67.     // Change the color of the LED strip using Bluetooth commands
  68.     if (Bluetooth_HC05_mySerial.available()) {
  69.         char command = Bluetooth_HC05_mySerial.read();
  70.         switch (command) {
  71.             case 'R':
  72.                 // Red color command
  73.                 digitalWrite(ledStripPin, HIGH);
  74.                 break;
  75.             case 'G':
  76.                 // Green color command
  77.                 digitalWrite(ledStripPin, LOW);
  78.                 break;
  79.             case 'B':
  80.                 // Blue color command
  81.                 digitalWrite(ledStripPin, HIGH);
  82.                 delay(500);
  83.                 digitalWrite(ledStripPin, LOW);
  84.                 delay(500);
  85.                 break;
  86.         }
  87.     }
  88. }
  89.  
  90. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement