Advertisement
pleasedontcode

LED Potentiometer rev_03

Oct 13th, 2024
90
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: LED Potentiometer
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2024-10-13 10:04:00
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* The RGB_blink project controls an LED connected to */
  21.     /* digital pin D2, utilizing a potentiometer on */
  22.     /* analog pin A0 to adjust time in between blinking. */
  23.     /* Ensure proper wiring and component compatibility */
  24.     /* for optimal performance. */
  25. /****** END SYSTEM REQUIREMENTS *****/
  26.  
  27. /****** DEFINITION OF LIBRARIES *****/
  28. #include <Arduino.h> // Include Arduino library for basic functions
  29.  
  30. /****** FUNCTION PROTOTYPES *****/
  31. void setup(void);
  32. void loop(void);
  33. void updateOutputs(void);
  34.  
  35. /***** DEFINITION OF ANALOG INPUT PINS *****/
  36. const uint8_t mypot_Potentiometer_Vout_PIN_A0 = A0; // Potentiometer connected to analog pin A0
  37.  
  38. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  39. const uint8_t myLed_LED_PIN_D2 = 2; // LED connected to digital pin D2
  40.  
  41. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  42. /***** used to store raw data *****/
  43. bool myLed_LED_PIN_D2_rawData = false; // Initialize to false for LED off
  44.  
  45. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  46. /***** used to store data after characteristic curve transformation *****/
  47. float myLed_LED_PIN_D2_phyData = 0.0;
  48.  
  49. // Timing variables
  50. unsigned long previousMillis = 0; // Store the last time LED was updated
  51. int blinkInterval = 1000; // Default blink interval (1 second)
  52.  
  53. void setup(void)
  54. {
  55.     // put your setup code here, to run once:
  56.     pinMode(mypot_Potentiometer_Vout_PIN_A0, INPUT); // Set potentiometer pin as input
  57.     pinMode(myLed_LED_PIN_D2, OUTPUT); // Set LED pin as output
  58. }
  59.  
  60. void loop(void)
  61. {
  62.     // put your main code here, to run repeatedly:
  63.     int potValue = analogRead(mypot_Potentiometer_Vout_PIN_A0); // Read the potentiometer value
  64.     blinkInterval = map(potValue, 0, 1023, 100, 2000); // Map the potentiometer value to a suitable blink interval
  65.  
  66.     unsigned long currentMillis = millis(); // Get the current time
  67.     if (currentMillis - previousMillis >= blinkInterval) // Check if it's time to blink the LED
  68.     {
  69.         previousMillis = currentMillis; // Save the last time the LED was updated
  70.         myLed_LED_PIN_D2_rawData = !myLed_LED_PIN_D2_rawData; // Toggle the LED state
  71.         updateOutputs(); // Refresh output data
  72.     }
  73. }
  74.  
  75. void updateOutputs()
  76. {
  77.     digitalWrite(myLed_LED_PIN_D2, myLed_LED_PIN_D2_rawData); // Write the LED state to the pin
  78. }
  79.  
  80. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement