Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Code by Tal Ofe - [email protected]
- Made for the bubble machine
- You can see it on YouTube
- https://www.youtube.com/watch?v=tMIEiQsoe-E
- */
- // servo library
- #include <Servo.h>
- // define needed infor for start and end point and pinout
- #define STARTPOS 100
- #define ENDPOS 35
- #define MOTORDIR 8
- #define MOTORPWM 10
- #define MOTORDESIREPWM 255
- Servo myservo; // create servo object to control a servo
- int pos = STARTPOS; // variable to store the servo position
- void setup() {
- //define pinout
- pinMode(MOTORDIR, OUTPUT);
- digitalWrite(MOTORDIR, LOW);
- pinMode(MOTORPWM, OUTPUT);
- digitalWrite(MOTORPWM, LOW);
- //servo
- myservo.attach(2); // attaches the servo on pin 2 to the servo object
- myservo.write(pos); // tell servo to go to position in variable 'pos'
- delay(15);
- }
- void loop() {
- // move the servo up
- for (pos = STARTPOS; pos >= ENDPOS; pos -= 1) {
- myservo.write(pos);
- delay(15);
- } //end for
- // start the fan motor
- setMotorPwm(MOTORDESIREPWM);
- // delay
- delay(1500);
- // set motor 0
- setMotorPwm(0);
- //delay
- delay(250);
- // move servo down
- for (pos = ENDPOS; pos <= STARTPOS; pos += 1) {
- // in steps of 1 degree
- myservo.write(pos);
- delay(15);
- } //end for
- // delay
- delay(250);
- } //end loop
- void setMotorPwm(byte pwm) {
- analogWrite(MOTORPWM, pwm);
- } //end void
Advertisement
Add Comment
Please, Sign In to add comment