pleasedontcode

Potentiometer Control rev_04

Oct 31st, 2025
474
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: Potentiometer Control
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2025-10-31 08:23:58
  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.  
  28. /* START CODE */
  29.  
  30. /****** DEFINITION OF LIBRARIES *****/
  31.  
  32. /****** FUNCTION PROTOTYPES *****/
  33. void setup(void);
  34. void loop(void);
  35.  
  36. /***** DEFINITION OF ANALOG INPUT PINS *****/
  37. const uint8_t mypot_Potentiometer_Vout_PIN_A0       = A0;
  38.  
  39. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  40. const uint8_t myLed_LED_PIN_D2      = 2;
  41.  
  42. // Variables to hold delay time
  43. unsigned long delayTime = 0;
  44.  
  45. // Variable to hold previous time
  46. unsigned long previousMillis = 0;
  47.  
  48. void setup(void)
  49. {
  50.     // put your setup code here, to run once:
  51.  
  52.     pinMode(mypot_Potentiometer_Vout_PIN_A0, INPUT);
  53.     pinMode(myLed_LED_PIN_D2, OUTPUT);
  54. }
  55.  
  56. void loop(void)
  57. {
  58.     // Read the potentiometer value (0-1023)
  59.     int sensorValue = analogRead(mypot_Potentiometer_Vout_PIN_A0);
  60.     // Map the potentiometer value to delay time (e.g., 0-2000 milliseconds)
  61.     delayTime = map(sensorValue, 0, 1023, 0, 2000);
  62.  
  63.     unsigned long currentMillis = millis();
  64.     if (currentMillis - previousMillis >= delayTime) {
  65.         // Save the last time LED was updated
  66.         previousMillis = currentMillis;
  67.         // Toggle the LED
  68.         digitalWrite(myLed_LED_PIN_D2, !digitalRead(myLed_LED_PIN_D2));
  69.     }
  70. }
  71.  
  72. /* END CODE */
  73.  
Advertisement
Add Comment
Please, Sign In to add comment