Advertisement
pleasedontcode

Potentiometer PWM rev_01

Dec 27th, 2023
79
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 PWM
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2023-12-28 05:08:01
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Increase or decrease the brightness of LED */
  21. /****** END SYSTEM REQUIREMENTS *****/
  22.  
  23. /****** DEFINITION OF LIBRARIES *****/
  24. #include <Arduino.h>
  25.  
  26. /***** DEFINITION OF ANALOG INPUT PINS *****/
  27. const uint8_t Input_Potentiometer_Vout_PIN_A0 = A0;
  28. const uint8_t PWM_Output_PIN = 9;
  29.  
  30. void setup(void)
  31. {
  32.   // put your setup code here, to run once:
  33.   pinMode(Input_Potentiometer_Vout_PIN_A0, INPUT);
  34.   pinMode(PWM_Output_PIN, OUTPUT);
  35. }
  36.  
  37. void loop(void)
  38. {
  39.   // put your main code here, to run repeatedly:
  40.   // Read the potentiometer value
  41.   int potValue = analogRead(Input_Potentiometer_Vout_PIN_A0);
  42.  
  43.   // Map the potentiometer value to the duty cycle range (0-255)
  44.   uint8_t dutyCycle = map(potValue, 0, 1023, 0, 255);
  45.  
  46.   // Set the duty cycle of the PWM using analogWrite
  47.   analogWrite(PWM_Output_PIN, dutyCycle);
  48.  
  49.   // Delay for stability
  50.   delay(10);
  51. }
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement