Advertisement
pleasedontcode

RC_CAR rev_43

Nov 3rd, 2023
94
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: RC_CAR
  13.     - Source Code compiled for: Arduino Nano
  14.     - Source Code created on: 2023-11-03 20:38:32
  15.     - Source Code generated by: Francesco Alessandro
  16.  
  17. ********* Pleasedontcode.com **********/
  18. /****** DEFINITION OF LIBRARIES *****/
  19. #include <Arduino.h>
  20. #include <Servo.h>
  21.  
  22. /****** SYSTEM REQUIREMENT 1 *****/
  23. /* Potentiometer reads a pressure sensor. If there is */
  24. /* a high pressure, close the first servo. If there is */
  25. /* a low pressure, close the second servo. If there */
  26. /* is no pressure, open both servos. */
  27.  
  28. /****** FUNCTION PROTOTYPES *****/
  29. void setup(void);
  30. void loop(void);
  31.  
  32. /***** DEFINITION OF ANALOG INPUT PINS *****/
  33. const uint8_t myPot_Potentiometer_Vout_PIN_A0 = A0;
  34.  
  35. /***** DEFINITION OF PWM OUTPUT PINS *****/
  36. const uint8_t servo_Servomotor_PWMSignal_PIN_D3 = 3;
  37. const uint8_t servo2_Servomotor_PWMSignal_PIN_D5 = 5;
  38.  
  39. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  40. Servo servo; // Instantiate Servo object for first servo
  41. Servo servo2; // Instantiate Servo object for second servo
  42.  
  43. void setup(void)
  44. {
  45.   // put your setup code here, to run once:
  46.   pinMode(myPot_Potentiometer_Vout_PIN_A0, INPUT);
  47.  
  48.   servo.attach(servo_Servomotor_PWMSignal_PIN_D3);     // Attach first servo to PWM pin D3
  49.   servo2.attach(servo2_Servomotor_PWMSignal_PIN_D5);   // Attach second servo to PWM pin D5
  50. }
  51.  
  52. void loop(void)
  53. {
  54.   // put your main code here, to run repeatedly:
  55.   int pressure = analogRead(myPot_Potentiometer_Vout_PIN_A0); // Read pressure value from the potentiometer
  56.  
  57.   if (pressure > 800) // High pressure, close the first servo
  58.   {
  59.     servo.write(0); // Set the angle of the first servo to 0 degrees (close position)
  60.   }
  61.   else if (pressure < 200) // Low pressure, close the second servo
  62.   {
  63.     servo2.write(0); // Set the angle of the second servo to 0 degrees (close position)
  64.   }
  65.   else // No pressure, open both servos
  66.   {
  67.     servo.write(180);   // Set the angle of the first servo to 180 degrees (open position)
  68.     servo2.write(180);  // Set the angle of the second servo to 180 degrees (open position)
  69.   }
  70.  
  71.   delay(100); // Delay for stability
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement