Advertisement
pleasedontcode

"Bluetooth LED Control" rev_02

Mar 27th, 2024
55
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 LED Control"
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2024-03-27 13:06:14
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Striscia led cambiamento luminosità e controllo */
  21.     /* tramite Bluetooth */
  22. /****** SYSTEM REQUIREMENT 2 *****/
  23.     /* Collega un applicazione al circuito per inviare i */
  24.     /* comandi */
  25. /****** END SYSTEM REQUIREMENTS *****/
  26.  
  27. /****** DEFINITION OF LIBRARIES *****/
  28. #include <SoftwareSerial.h>
  29.  
  30. /****** FUNCTION PROTOTYPES *****/
  31. void setup(void);
  32. void loop(void);
  33.  
  34. /****** SYSTEM REQUIREMENTS *****/
  35. // SYSTEM REQUIREMENT 1: Striscia led cambiamento luminosità e controllo tramite Bluetooth
  36. const uint8_t LED_PIN = 9; // Pin connected to the LED strip
  37.  
  38. // SYSTEM REQUIREMENT 2: Collega un applicazione al circuito per inviare i comandi
  39. const uint8_t Bluetooth_HC05_mySerial_PIN_SERIAL_TX_A0 = A0; // Bluetooth module TX pin connected to Arduino A0
  40. const uint8_t Bluetooth_HC05_mySerial_PIN_SERIAL_RX_A1 = A1; // Bluetooth module RX pin connected to Arduino A1
  41. SoftwareSerial Bluetooth_HC05_mySerial(Bluetooth_HC05_mySerial_PIN_SERIAL_RX_A1, Bluetooth_HC05_mySerial_PIN_SERIAL_TX_A0);
  42.  
  43. void setup(void)
  44. {
  45.     // put your setup code here, to run once:
  46.     pinMode(LED_PIN, OUTPUT); // Set LED pin as output
  47.     Bluetooth_HC05_mySerial.begin(9600); // Initialize Bluetooth serial communication
  48. }
  49.  
  50. void loop(void)
  51. {
  52.     // put your main code here, to run repeatedly:
  53.     if (Bluetooth_HC05_mySerial.available()) {
  54.         // Read the incoming command from Bluetooth
  55.         char command = Bluetooth_HC05_mySerial.read();
  56.  
  57.         // Perform action based on the received command
  58.         switch (command) {
  59.             case '0': // Turn off the LED
  60.                 digitalWrite(LED_PIN, LOW);
  61.                 break;
  62.             case '1': // Turn on the LED
  63.                 digitalWrite(LED_PIN, HIGH);
  64.                 break;
  65.             default:
  66.                 break;
  67.         }
  68.     }
  69. }
  70.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement