/********* 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: Flight Controller - Source Code compiled for: Arduino Uno - Source Code created on: 2024-03-14 07:44:18 ********* Pleasedontcode.com **********/ /****** SYSTEM REQUIREMENTS *****/ /****** SYSTEM REQUIREMENT 1 *****/ /* brushed motors flight contoller */ /****** END SYSTEM REQUIREMENTS *****/ /****** DEFINITION OF LIBRARIES *****/ /****** FUNCTION PROTOTYPES *****/ void setup(void); void loop(void); /***** DEFINITION OF ANALOG INPUT PINS *****/ const uint8_t nn_Potentiometer_Vout_PIN_A0 = A0; /****** SYSTEM REQUIREMENTS *****/ /****** SYSTEM REQUIREMENT 1 *****/ /* brushed motors flight controller */ /* Define the Pins for Motor Control */ const uint8_t motor1Pin1 = 2; const uint8_t motor1Pin2 = 3; const uint8_t motor2Pin1 = 4; const uint8_t motor2Pin2 = 5; void setup(void) { // put your setup code here, to run once: pinMode(nn_Potentiometer_Vout_PIN_A0, INPUT); // Setup motor control pins as outputs pinMode(motor1Pin1, OUTPUT); pinMode(motor1Pin2, OUTPUT); pinMode(motor2Pin1, OUTPUT); pinMode(motor2Pin2, OUTPUT); } void loop(void) { // put your main code here, to run repeatedly: // Read the potentiometer value int potValue = analogRead(nn_Potentiometer_Vout_PIN_A0); // Map the potentiometer value to motor speed range int motorSpeed = map(potValue, 0, 1023, -255, 255); // Set the motor speeds based on the potentiometer value if (motorSpeed >= 0) { analogWrite(motor1Pin1, motorSpeed); analogWrite(motor1Pin2, 0); analogWrite(motor2Pin1, motorSpeed); analogWrite(motor2Pin2, 0); } else { analogWrite(motor1Pin1, 0); analogWrite(motor1Pin2, abs(motorSpeed)); analogWrite(motor2Pin1, 0); analogWrite(motor2Pin2, abs(motorSpeed)); } delay(100); }