Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* Pleasedontcode.com **********
- Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- - Terms and Conditions:
- You have a non-exclusive, revocable, worldwide, royalty-free license
- for personal and commercial use. Attribution is optional; modifications
- are allowed, but you're responsible for code maintenance. We're not
- liable for any loss or damage. For full terms,
- please visit pleasedontcode.com/termsandconditions.
- - Project: "Digital Setup"
- - Source Code compiled for: Arduino Uno
- - Source Code created on: 2024-03-27 12:51:18
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* Striscia led cambiamento luminosità e controllo */
- /* tramite Bluetooth */
- /****** END SYSTEM REQUIREMENTS *****/
- /****** DEFINITION OF LIBRARIES *****/
- #include <SoftwareSerial.h>
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void updateOutputs(void);
- void parseSerialData(void);
- /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
- const uint8_t Striscialed_LEDRGB_Red_PIN_D2 = 2;
- const uint8_t Striscialed_LEDRGB_Green_PIN_D3 = 3;
- const uint8_t Striscialed_LEDRGB_Blue_PIN_D4 = 4;
- /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
- /***** used to store raw data *****/
- bool Striscialed_LEDRGB_Red_PIN_D2_rawData = 0;
- bool Striscialed_LEDRGB_Green_PIN_D3_rawData = 0;
- bool Striscialed_LEDRGB_Blue_PIN_D4_rawData = 0;
- /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
- /***** used to store data after characteristic curve transformation *****/
- float Striscialed_LEDRGB_Red_PIN_D2_phyData = 0.0;
- float Striscialed_LEDRGB_Green_PIN_D3_phyData = 0.0;
- float Striscialed_LEDRGB_Blue_PIN_D4_phyData = 0.0;
- /***** DEFINITION OF BLUETOOTH VARIABLES *****/
- const uint8_t Bluetooth_RX_PIN_D5 = 5;
- const uint8_t Bluetooth_TX_PIN_D6 = 6;
- SoftwareSerial bluetoothSerial(Bluetooth_RX_PIN_D5, Bluetooth_TX_PIN_D6); // RX, TX
- void setup(void)
- {
- // put your setup code here, to run once:
- pinMode(Striscialed_LEDRGB_Red_PIN_D2, OUTPUT);
- pinMode(Striscialed_LEDRGB_Green_PIN_D3, OUTPUT);
- pinMode(Striscialed_LEDRGB_Blue_PIN_D4, OUTPUT);
- bluetoothSerial.begin(9600);
- }
- void loop(void)
- {
- // put your main code here, to run repeatedly:
- updateOutputs(); // Refresh output data
- parseSerialData(); // Check for incoming serial data
- }
- void updateOutputs()
- {
- digitalWrite(Striscialed_LEDRGB_Red_PIN_D2, Striscialed_LEDRGB_Red_PIN_D2_rawData);
- digitalWrite(Striscialed_LEDRGB_Green_PIN_D3, Striscialed_LEDRGB_Green_PIN_D3_rawData);
- digitalWrite(Striscialed_LEDRGB_Blue_PIN_D4, Striscialed_LEDRGB_Blue_PIN_D4_rawData);
- }
- void parseSerialData()
- {
- while (bluetoothSerial.available())
- {
- char data = bluetoothSerial.read();
- // Check if the received data is a valid brightness value
- if (data >= '0' && data <= '9')
- {
- float brightness = map(data - '0', 0, 9, 0, 255); // Map the received value to the range 0-255
- Striscialed_LEDRGB_Red_PIN_D2_rawData = brightness;
- Striscialed_LEDRGB_Green_PIN_D3_rawData = brightness;
- Striscialed_LEDRGB_Blue_PIN_D4_rawData = brightness;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement