Advertisement
pleasedontcode

2_servo_wireless rev_01

Oct 20th, 2023
85
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: 2_servo_wireless
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2023-10-20 07:54:39
  15.     - Source Code generated by: Lohith bala
  16.  
  17. ********* Pleasedontcode.com **********/
  18. /****** DEFINITION OF LIBRARIES *****/
  19. #include <Arduino.h>
  20. #include <EasyButton.h>
  21. #include <Servo.h>
  22.  
  23. /****** SYSTEM REQUIREMENT 1 *****/
  24. /* Should be able to manually control the servo using */
  25. /* potentiometer */
  26.  
  27. /****** FUNCTION PROTOTYPES *****/
  28. void setup(void);
  29. void loop(void);
  30.  
  31. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  32. const uint8_t Lava_PushButton_PIN_D2 = 2; // Define the pin number for the push button
  33.  
  34. /***** DEFINITION OF ANALOG INPUT PINS *****/
  35. const uint8_t Potentiometer_PIN_A0 = A0; // Define the pin number for the potentiometer
  36.  
  37. /***** DEFINITION OF SERVO OUTPUT PINS *****/
  38. const uint8_t Servo_PIN_D9 = 9; // Define the pin number for the servo
  39.  
  40. /***** GLOBAL VARIABLES *****/
  41. Servo servo; // Create a servo object
  42.  
  43. void setup(void)
  44. {
  45.   // put your setup code here, to run once:
  46.  
  47.   pinMode(Lava_PushButton_PIN_D2, INPUT_PULLUP); // Set the push button pin as input with internal pull-up resistor
  48.  
  49.   servo.attach(Servo_PIN_D9); // Attach the servo to the servo pin
  50. }
  51.  
  52. void loop(void)
  53. {
  54.   // put your main code here, to run repeatedly:
  55.  
  56.   int potValue = analogRead(Potentiometer_PIN_A0); // Read the analog value from the potentiometer
  57.   int servoPos = map(potValue, 0, 1023, 0, 180); // Map the potentiometer value to servo position (0-180 degrees)
  58.  
  59.   servo.write(servoPos); // Set the servo position based on the potentiometer value
  60.  
  61.   delay(10); // Delay for stability
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement