Advertisement
pleasedontcode

"Digital Setup" rev_01

Mar 27th, 2024
68
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: "Digital Setup"
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2024-03-27 12:51:18
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Striscia led cambiamento luminosità e controllo */
  21.     /* tramite Bluetooth */
  22. /****** END SYSTEM REQUIREMENTS *****/
  23.  
  24. /****** DEFINITION OF LIBRARIES *****/
  25. #include <SoftwareSerial.h>
  26.  
  27. /****** FUNCTION PROTOTYPES *****/
  28. void setup(void);
  29. void loop(void);
  30. void updateOutputs(void);
  31. void parseSerialData(void);
  32.  
  33. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  34. const uint8_t Striscialed_LEDRGB_Red_PIN_D2 = 2;
  35. const uint8_t Striscialed_LEDRGB_Green_PIN_D3 = 3;
  36. const uint8_t Striscialed_LEDRGB_Blue_PIN_D4 = 4;
  37.  
  38. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  39. /***** used to store raw data *****/
  40. bool Striscialed_LEDRGB_Red_PIN_D2_rawData = 0;
  41. bool Striscialed_LEDRGB_Green_PIN_D3_rawData = 0;
  42. bool Striscialed_LEDRGB_Blue_PIN_D4_rawData = 0;
  43.  
  44. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  45. /***** used to store data after characteristic curve transformation *****/
  46. float Striscialed_LEDRGB_Red_PIN_D2_phyData = 0.0;
  47. float Striscialed_LEDRGB_Green_PIN_D3_phyData = 0.0;
  48. float Striscialed_LEDRGB_Blue_PIN_D4_phyData = 0.0;
  49.  
  50. /***** DEFINITION OF BLUETOOTH VARIABLES *****/
  51. const uint8_t Bluetooth_RX_PIN_D5 = 5;
  52. const uint8_t Bluetooth_TX_PIN_D6 = 6;
  53. SoftwareSerial bluetoothSerial(Bluetooth_RX_PIN_D5, Bluetooth_TX_PIN_D6); // RX, TX
  54.  
  55. void setup(void)
  56. {
  57.   // put your setup code here, to run once:
  58.  
  59.   pinMode(Striscialed_LEDRGB_Red_PIN_D2, OUTPUT);
  60.   pinMode(Striscialed_LEDRGB_Green_PIN_D3, OUTPUT);
  61.   pinMode(Striscialed_LEDRGB_Blue_PIN_D4, OUTPUT);
  62.  
  63.   bluetoothSerial.begin(9600);
  64. }
  65.  
  66. void loop(void)
  67. {
  68.   // put your main code here, to run repeatedly:
  69.  
  70.   updateOutputs(); // Refresh output data
  71.   parseSerialData(); // Check for incoming serial data
  72. }
  73.  
  74. void updateOutputs()
  75. {
  76.   digitalWrite(Striscialed_LEDRGB_Red_PIN_D2, Striscialed_LEDRGB_Red_PIN_D2_rawData);
  77.   digitalWrite(Striscialed_LEDRGB_Green_PIN_D3, Striscialed_LEDRGB_Green_PIN_D3_rawData);
  78.   digitalWrite(Striscialed_LEDRGB_Blue_PIN_D4, Striscialed_LEDRGB_Blue_PIN_D4_rawData);
  79. }
  80.  
  81. void parseSerialData()
  82. {
  83.   while (bluetoothSerial.available())
  84.   {
  85.     char data = bluetoothSerial.read();
  86.    
  87.     // Check if the received data is a valid brightness value
  88.     if (data >= '0' && data <= '9')
  89.     {
  90.       float brightness = map(data - '0', 0, 9, 0, 255); // Map the received value to the range 0-255
  91.       Striscialed_LEDRGB_Red_PIN_D2_rawData = brightness;
  92.       Striscialed_LEDRGB_Green_PIN_D3_rawData = brightness;
  93.       Striscialed_LEDRGB_Blue_PIN_D4_rawData = brightness;
  94.     }
  95.   }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement