Created
July 14, 2018 07:46
-
-
Save 3Dsketcha/30bc05b60bd94d2d6cb17ba96dc99ca8 to your computer and use it in GitHub Desktop.
iPad Autoclicker - with Arduino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Servo.h> | |
Servo myservo_green; // create servo object to control a servo | |
Servo myservo_red; | |
Servo myservo_yellow; | |
Servo myservo_blue; | |
// twelve servo objects can be created on most boards | |
int pos = 0; // variable to store the servo position | |
void setup() { | |
myservo_green.attach(7); // attaches the servo on pin 9 to the servo object | |
myservo_red.attach(8); | |
myservo_yellow.attach(9); | |
myservo_blue.attach(10); | |
delay(1000); | |
myservo_green.write(10); | |
myservo_red.write(10); | |
myservo_yellow.write(10); | |
myservo_blue.write(10); | |
delay(1000); | |
myservo_green.detach(); | |
myservo_red.detach(); | |
myservo_yellow.detach(); | |
myservo_blue.detach(); | |
} | |
void loop() { | |
myservo_green.attach(7); // attaches the servo on pin 9 to the servo object | |
//---------------------------------------------------------------------------- | |
for (pos = 10; pos <= 135; pos += 1) { // goes from 0 degrees to 180 degrees | |
// in steps of 1 degree | |
myservo_green.write(pos); // tell servo to go to position in variable 'pos' | |
delay(7); // waits 15ms for the servo to reach the position | |
} | |
delay(1000); | |
for (pos = 135; pos >= 10; pos -= 1) { // goes from 180 degrees to 0 degrees | |
myservo_green.write(pos); // tell servo to go to position in variable 'pos' | |
delay(4); // waits 15ms for the servo to reach the position | |
} | |
myservo_green.detach(); | |
delay(34000); | |
myservo_red.attach(8); // attaches the servo on pin 9 to the servo object | |
//-------------------------------------------------------------------------- | |
for (pos = 10; pos <= 140; pos += 1) { // goes from 0 degrees to 180 degrees | |
// in steps of 1 degree | |
myservo_red.write(pos); // tell servo to go to position in variable 'pos' | |
delay(8); // waits 15ms for the servo to reach the position | |
} | |
myservo_yellow.attach(9); // attaches the servo on pin 9 to the servo object | |
//----------------------------------------------------------------------------- | |
for (pos = 10; pos <= 140; pos += 1) { // goes from 0 degrees to 180 degrees | |
// in steps of 1 degree | |
myservo_yellow.write(pos); // tell servo to go to position in variable 'pos' | |
delay(8); // waits 15ms for the servo to reach the position | |
} | |
delay(1000); | |
for (pos = 140; pos >= 10; pos -= 1) { // goes from 180 degrees to 0 degrees | |
myservo_red.write(pos); // tell servo to go to position in variable 'pos' | |
delay(4); // waits 15ms for the servo to reach the position | |
} | |
myservo_red.detach(); | |
for (pos = 140; pos >= 10; pos -= 1) { // goes from 180 degrees to 0 degrees | |
myservo_yellow.write(pos); // tell servo to go to position in variable 'pos' | |
delay(4); // waits 15ms for the servo to reach the position | |
} | |
myservo_yellow.detach(); | |
delay(2000); | |
myservo_blue.attach(10); // attaches the servo on pin 9 to the servo object | |
//----------------------------------------------------------------------------- | |
for (pos = 10; pos <= 190; pos += 1) { // goes from 0 degrees to 180 degrees | |
// in steps of 1 degree | |
myservo_blue.write(pos); // tell servo to go to position in variable 'pos' | |
delay(8); // waits 15ms for the servo to reach the position | |
} | |
delay(800); | |
for (pos = 190; pos >= 10; pos -= 1) { // goes from 180 degrees to 0 degrees | |
myservo_blue.write(pos); // tell servo to go to position in variable 'pos' | |
delay(4); // waits 15ms for the servo to reach the position | |
} | |
myservo_blue.detach(); | |
delay(1500); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just my first Arduino Code for an iPad Autoclicker orking with 4 servomotors.