Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* 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: "Servo Control"
- - Source Code NOT compiled for: Arduino Uno
- - Source Code created on: 2024-11-23 16:01:18
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* Servo Motors move when potentiometer degrees are */
- /* changed. */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <Servo.h>
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- // Define the number of servos and potentiometers
- #define NUM_SERVOS 4
- // Define arrays for potentiometer pins and servo objects
- int potPins[NUM_SERVOS] = {A0, A1, A2, A3}; // Potentiometer pins
- Servo myServos[NUM_SERVOS]; // Servo objects
- int vals[NUM_SERVOS]; // Store potentiometer values
- void setup(void)
- {
- // Start serial communication for debugging
- Serial.begin(9600);
- // Attach servos to digital pins 6, 7, 8, and 9
- for (int i = 0; i < NUM_SERVOS; i++) {
- myServos[i].attach(6 + i); // Attach servos to pins 6, 7, 8, 9
- }
- }
- void loop(void)
- {
- // Read potentiometer values and map them to servo angles
- for (int i = 0; i < NUM_SERVOS; i++) {
- vals[i] = analogRead(potPins[i]); // Read potentiometer value
- vals[i] = map(vals[i], 0, 1023, 0, 180); // Map to servo angle (0-180)
- myServos[i].write(vals[i]); // Write the mapped value to the servo
- // Print the current servo value to the Serial Monitor
- Serial.print("Servo ");
- Serial.print(i);
- Serial.print(": ");
- Serial.println(vals[i]);
- // Short delay for stability
- delay(10);
- }
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement