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 compiled for: Arduino Nano
- - Source Code created on: 2023-12-28 06:14:52
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* i want to attach two servo to swap in opposite */
- /* direction */
- /****** SYSTEM REQUIREMENT 2 *****/
- /* i want to attach 8 servo to make a humanoid robot */
- /****** END SYSTEM REQUIREMENTS *****/
- /****** DEFINITION OF LIBRARIES *****/
- #include <Arduino.h>
- #include <Servo.h>
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- /***** DEFINITION OF PWM OUTPUT PINS *****/
- const uint8_t servo1_PIN = 3;
- const uint8_t servo2_PIN = 5;
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- Servo servo1;
- Servo servo2;
- Servo servo3;
- Servo servo4;
- Servo servo5;
- Servo servo6;
- Servo servo7;
- Servo servo8;
- void setup(void)
- {
- // put your setup code here, to run once:
- servo1.attach(servo1_PIN);
- servo2.attach(servo2_PIN);
- // Attach additional servos for humanoid robot
- servo3.attach(6);
- servo4.attach(9);
- servo5.attach(10);
- servo6.attach(11);
- servo7.attach(12);
- servo8.attach(13);
- }
- void loop(void)
- {
- // put your main code here, to run repeatedly:
- /****** SYSTEM REQUIREMENT 1 *****/
- // Swap servo1 and servo2 in opposite directions
- for (int pos = 0; pos <= 180; pos += 1) {
- servo1.write(pos);
- servo2.write(180 - pos);
- delay(15);
- }
- /****** SYSTEM REQUIREMENT 2 *****/
- // Move all the servos for the humanoid robot
- for (int pos = 0; pos <= 180; pos += 1) {
- servo3.write(pos);
- servo4.write(pos);
- servo5.write(pos);
- servo6.write(pos);
- servo7.write(pos);
- servo8.write(pos);
- delay(15);
- }
- for (int pos = 180; pos >= 0; pos -= 1) {
- servo3.write(pos);
- servo4.write(pos);
- servo5.write(pos);
- servo6.write(pos);
- servo7.write(pos);
- servo8.write(pos);
- delay(15);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement