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: LED Potentiometer
- - Source Code NOT compiled for: Arduino Uno
- - Source Code created on: 2024-10-13 10:04:00
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* The RGB_blink project controls an LED connected to */
- /* digital pin D2, utilizing a potentiometer on */
- /* analog pin A0 to adjust time in between blinking. */
- /* Ensure proper wiring and component compatibility */
- /* for optimal performance. */
- /****** END SYSTEM REQUIREMENTS *****/
- /****** DEFINITION OF LIBRARIES *****/
- #include <Arduino.h> // Include Arduino library for basic functions
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void updateOutputs(void);
- /***** DEFINITION OF ANALOG INPUT PINS *****/
- const uint8_t mypot_Potentiometer_Vout_PIN_A0 = A0; // Potentiometer connected to analog pin A0
- /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
- const uint8_t myLed_LED_PIN_D2 = 2; // LED connected to digital pin D2
- /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
- /***** used to store raw data *****/
- bool myLed_LED_PIN_D2_rawData = false; // Initialize to false for LED off
- /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
- /***** used to store data after characteristic curve transformation *****/
- float myLed_LED_PIN_D2_phyData = 0.0;
- // Timing variables
- unsigned long previousMillis = 0; // Store the last time LED was updated
- int blinkInterval = 1000; // Default blink interval (1 second)
- void setup(void)
- {
- // put your setup code here, to run once:
- pinMode(mypot_Potentiometer_Vout_PIN_A0, INPUT); // Set potentiometer pin as input
- pinMode(myLed_LED_PIN_D2, OUTPUT); // Set LED pin as output
- }
- void loop(void)
- {
- // put your main code here, to run repeatedly:
- int potValue = analogRead(mypot_Potentiometer_Vout_PIN_A0); // Read the potentiometer value
- blinkInterval = map(potValue, 0, 1023, 100, 2000); // Map the potentiometer value to a suitable blink interval
- unsigned long currentMillis = millis(); // Get the current time
- if (currentMillis - previousMillis >= blinkInterval) // Check if it's time to blink the LED
- {
- previousMillis = currentMillis; // Save the last time the LED was updated
- myLed_LED_PIN_D2_rawData = !myLed_LED_PIN_D2_rawData; // Toggle the LED state
- updateOutputs(); // Refresh output data
- }
- }
- void updateOutputs()
- {
- digitalWrite(myLed_LED_PIN_D2, myLed_LED_PIN_D2_rawData); // Write the LED state to the pin
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement