Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Gabby Shimoni 02062019
- // Move DC motor back and forth
- #define motorInPin1 7
- #define motorInPin2 8
- #define enablePin 9
- void setup() {
- pinMode(motorInPin1, OUTPUT);
- pinMode(motorInPin2, OUTPUT);
- pinMode(enablePin, OUTPUT);
- }
- void loop() {
- // speed up clockwise
- for (int Speed = 50; Speed <= 250; Speed += 50) {
- analogWrite(enablePin, Speed);
- digitalWrite(motorInPin1, HIGH);
- digitalWrite(motorInPin2, LOW);
- delay(2000);
- }
- // slow down clockwise
- for (int Speed = 250; Speed >= 50; Speed -= 50) {
- analogWrite(enablePin, Speed);
- digitalWrite(motorInPin1, HIGH);
- digitalWrite(motorInPin2, LOW);
- delay(2000);
- }
- // stop motor
- analogWrite(enablePin, 0);
- delay(1000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement