/********* Pleasedontcode.com **********
Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- Terms and Conditions:
You have a non-exclusive, revocable, worldwide, royalty-free license
for personal and commercial use. Attribution is optional; modifications
are allowed, but you're responsible for code maintenance. We're not
liable for any loss or damage. For full terms,
please visit pleasedontcode.com/termsandconditions.
- Project: RC_CAR
- Source Code compiled for: Arduino Nano
- Source Code created on: 2023-11-03 20:38:32
- Source Code generated by: Francesco Alessandro
********* Pleasedontcode.com **********/
/****** DEFINITION OF LIBRARIES *****/
#include
#include
/****** SYSTEM REQUIREMENT 1 *****/
/* Potentiometer reads a pressure sensor. If there is */
/* a high pressure, close the first servo. If there is */
/* a low pressure, close the second servo. If there */
/* is no pressure, open both servos. */
/****** FUNCTION PROTOTYPES *****/
void setup(void);
void loop(void);
/***** DEFINITION OF ANALOG INPUT PINS *****/
const uint8_t myPot_Potentiometer_Vout_PIN_A0 = A0;
/***** DEFINITION OF PWM OUTPUT PINS *****/
const uint8_t servo_Servomotor_PWMSignal_PIN_D3 = 3;
const uint8_t servo2_Servomotor_PWMSignal_PIN_D5 = 5;
/****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
Servo servo; // Instantiate Servo object for first servo
Servo servo2; // Instantiate Servo object for second servo
void setup(void)
{
// put your setup code here, to run once:
pinMode(myPot_Potentiometer_Vout_PIN_A0, INPUT);
servo.attach(servo_Servomotor_PWMSignal_PIN_D3); // Attach first servo to PWM pin D3
servo2.attach(servo2_Servomotor_PWMSignal_PIN_D5); // Attach second servo to PWM pin D5
}
void loop(void)
{
// put your main code here, to run repeatedly:
int pressure = analogRead(myPot_Potentiometer_Vout_PIN_A0); // Read pressure value from the potentiometer
if (pressure > 800) // High pressure, close the first servo
{
servo.write(0); // Set the angle of the first servo to 0 degrees (close position)
}
else if (pressure < 200) // Low pressure, close the second servo
{
servo2.write(0); // Set the angle of the second servo to 0 degrees (close position)
}
else // No pressure, open both servos
{
servo.write(180); // Set the angle of the first servo to 180 degrees (open position)
servo2.write(180); // Set the angle of the second servo to 180 degrees (open position)
}
delay(100); // Delay for stability
}