Advertisement
pleasedontcode

**Potentiometer Control** rev_01

Jun 13th, 2025
355
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-06-13 17:33:55
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Capture the analog input from a potentiometer */
  21.     /* connected to A0, and trigger a specific action */
  22.     /* (e.g., turning on/off an LED) when the voltage */
  23.     /* exceeds a defined threshold, enhancing user */
  24.     /* interaction with the device. */
  25. /****** END SYSTEM REQUIREMENTS *****/
  26.  
  27. /* START CODE */
  28.  
  29. /****** DEFINITION OF LIBRARIES *****/
  30.  
  31. /****** FUNCTION PROTOTYPES *****/
  32. void setup(void);
  33. void loop(void);
  34. void updateOutputs(void);
  35. void checkPotentiometer(void);
  36.  
  37. /***** DEFINITION OF ANALOG INPUT PINS *****/
  38. const uint8_t potm_Potentiometer_Vout_PIN_A0 = A0;
  39.  
  40. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  41. const uint8_t myLED_LED_PIN_D2 = 2;
  42.  
  43. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  44. /***** used to store raw data *****/
  45. bool myLED_LED_PIN_D2_rawData = 0;
  46.  
  47. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  48. /***** used to store data after characteristic curve transformation *****/
  49. float myLED_LED_PIN_D2_phyData = 0.0;
  50.  
  51. /***** DEFINITION OF THRESHOLD *****/
  52. const int threshold = 512; // Define threshold for potentiometer value
  53.  
  54. void setup(void)
  55. {
  56.     // put your setup code here, to run once:
  57.     pinMode(potm_Potentiometer_Vout_PIN_A0, INPUT);
  58.     pinMode(myLED_LED_PIN_D2, OUTPUT);
  59. }
  60.  
  61. void loop(void)
  62. {
  63.     // put your main code here, to run repeatedly:
  64.     checkPotentiometer(); // Check the potentiometer value
  65.     updateOutputs(); // Refresh output data
  66. }
  67.  
  68. void checkPotentiometer()
  69. {
  70.     int potValue = analogRead(potm_Potentiometer_Vout_PIN_A0); // Read the potentiometer value
  71.     if (potValue > threshold) {
  72.         myLED_LED_PIN_D2_rawData = true; // Turn on LED if above threshold
  73.     } else {
  74.         myLED_LED_PIN_D2_rawData = false; // Turn off LED if below threshold
  75.     }
  76. }
  77.  
  78. void updateOutputs()
  79. {
  80.     digitalWrite(myLED_LED_PIN_D2, myLED_LED_PIN_D2_rawData);
  81. }
  82.  
  83. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement