Advertisement
pleasedontcode

"Potentiometer Mapping" rev_11

Jun 21st, 2024
472
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 Mapping"
  13.     - Source Code compiled for: Arduino Mega
  14.     - Source Code created on: 2024-06-21 08:13:57
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Convert potentiometer signal to ppm */
  21. /****** END SYSTEM REQUIREMENTS *****/
  22.  
  23. /****** DEFINITION OF LIBRARIES *****/
  24. #include <PPMEncoder.h>  //http://github.com/schinken/PPMEncoder
  25.  
  26. /****** FUNCTION PROTOTYPES *****/
  27. void setup(void);
  28. void loop(void);
  29.  
  30. /***** DEFINITION OF ANALOG INPUT PINS *****/
  31. const uint8_t steering_Potentiometer_Vout_PIN_A0 = A0;
  32.  
  33. /****** DEFINITION OF CONSTANTS *****/
  34. #define OUTPUT_PIN 10  // Define the output pin for PPM signal
  35.  
  36. void setup(void)
  37. {
  38.   // put your setup code here, to run once:
  39.  
  40.   pinMode(steering_Potentiometer_Vout_PIN_A0, INPUT);  // Set the potentiometer pin as input
  41.   ppmEncoder.begin(OUTPUT_PIN);  // Initialize the PPM encoder on the defined output pin
  42. }
  43.  
  44. void loop(void)
  45. {
  46.   // put your main code here, to run repeatedly:
  47.  
  48.   int potValue = analogRead(steering_Potentiometer_Vout_PIN_A0);  // Read the potentiometer value
  49.   int ppmValue = map(potValue, 0, 1023, PPMEncoder::MIN, PPMEncoder::MAX);  // Map the potentiometer value to PPM range
  50.  
  51.   ppmEncoder.setChannel(0, ppmValue);  // Set the PPM value for channel 0
  52. }
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement