Advertisement
pleasedontcode

PotPWM rev_01

Nov 26th, 2023
61
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: PotPWM
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2023-11-26 07:50:41
  15.     - Source Code generated by: Mohd
  16.  
  17. ********* Pleasedontcode.com **********/
  18. /****** DEFINITION OF LIBRARIES *****/
  19. #include <Arduino.h>
  20.  
  21. /****** SYSTEM REQUIREMENT 1 *****/
  22.   /* PWM varies with potentiometer */
  23.  
  24. /****** SYSTEM REQUIREMENT 2 *****/
  25.   /* PWM varies with input potentiometer */
  26.  
  27. /****** SUBSYSTEM REQUIREMENTS *****/
  28.   /* Subsystem Requirement 1: Read potentiometer value */
  29.   /* Subsystem Requirement 2: Map potentiometer value to PWM range */
  30.   /* Subsystem Requirement 3: Set PWM output value */
  31.  
  32. /****** FUNCTION PROTOTYPES *****/
  33. void setup(void);
  34. void loop(void);
  35.  
  36. /***** DEFINITION OF ANALOG INPUT PINS *****/
  37. const uint8_t Pot_Potentiometer_Vout_PIN_A0 = A0;
  38.  
  39. /***** DEFINITION OF PWM OUTPUT PIN *****/
  40. const uint8_t PWM_Output_PIN_3 = 3;
  41.  
  42. void setup(void)
  43. {
  44.   // Set the potentiometer pin as input
  45.   pinMode(Pot_Potentiometer_Vout_PIN_A0, INPUT);
  46.  
  47.   // Set the PWM output pin as output
  48.   pinMode(PWM_Output_PIN_3, OUTPUT);
  49. }
  50.  
  51. void loop(void)
  52. {
  53.   // Subsystem Requirement 1: Read the potentiometer value
  54.   int potValue = analogRead(Pot_Potentiometer_Vout_PIN_A0);
  55.  
  56.   // Subsystem Requirement 2: Map the potentiometer value to the PWM range (0-255)
  57.   int pwmValue = map(potValue, 0, 1023, 0, 255);
  58.  
  59.   // Subsystem Requirement 3: Set the PWM output value
  60.   analogWrite(PWM_Output_PIN_3, pwmValue);
  61. }
  62.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement