Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Motor A
- int motor1Pin1 = 13; //sárga
- int motor1Pin2 = 12; //narancs
- int motor1En = 26; //zöld
- // Motor B
- int motor2Pin1 = 14; //
- int motor2Pin2 = 27;
- int motor2En = 25; //kék
- // Setting PWM properties
- const int freq = 30000;
- const int pwmChannel = 0;
- const int resolution = 8;
- int dutyCycle = 200;
- void setup() {
- // sets the pins as outputs:
- pinMode(motor1Pin1, OUTPUT);
- pinMode(motor1Pin2, OUTPUT);
- pinMode(motor2Pin1, OUTPUT);
- pinMode(motor2Pin2, OUTPUT);
- // configure LED PWM functionalitites
- ledcSetup(pwmChannel, freq, resolution);
- // attach the channel to the GPIO to be controlled
- ledcAttachPin(motor1En, pwmChannel);
- ledcAttachPin(motor2En, pwmChannel);
- Serial.begin(115200);
- // testing
- Serial.print("Testing DC Motor...");
- }
- void loop() {
- /*
- // Move the DC motor 1 forward at maximum speed
- Serial.println("Moving Forward");
- digitalWrite(motor1Pin1, LOW);
- digitalWrite(motor1Pin2, HIGH);
- delay(2000);
- // Stop the DC motor 1
- Serial.println("Motor stopped");
- digitalWrite(motor1Pin1, LOW);
- digitalWrite(motor1Pin2, LOW);
- delay(1000);
- // Move DC motor 1 backwards at maximum speed
- Serial.println("Moving Backwards");
- digitalWrite(motor1Pin1, HIGH);
- digitalWrite(motor1Pin2, LOW);
- delay(2000);
- // Stop the DC motor 1
- Serial.println("Motor stopped");
- digitalWrite(motor1Pin1, LOW);
- digitalWrite(motor1Pin2, LOW);
- delay(1000);
- // Move DC motor 2 forward with increasing speed
- Serial.println("Motor 2 fwd 100");
- digitalWrite(motor2Pin1, HIGH);
- digitalWrite(motor2Pin2, LOW);
- ledcWrite(pwmChannel, 100);
- delay(1000);
- */
- // Move DC motor 1 forward with increasing speed
- Serial.println("Motor fwd 100");
- digitalWrite(motor1Pin1, HIGH);
- digitalWrite(motor1Pin2, LOW);
- ledcWrite(pwmChannel, 100);
- delay(1000);
- Serial.println("Motor stopped");
- digitalWrite(motor1Pin1, LOW);
- digitalWrite(motor1Pin2, LOW);
- delay(1000);
- Serial.println("Motor fwd 150");
- digitalWrite(motor1Pin1, HIGH);
- digitalWrite(motor1Pin2, LOW);
- ledcWrite(pwmChannel, 150);
- delay(1000);
- Serial.println("Motor stopped");
- digitalWrite(motor1Pin1, LOW);
- digitalWrite(motor1Pin2, LOW);
- delay(1000);
- //--------------------motor 2
- // Move DC motor 1 forward with increasing speed
- Serial.println("Motor fwd 100");
- digitalWrite(motor2Pin1, HIGH);
- digitalWrite(motor2Pin2, LOW);
- ledcWrite(pwmChannel, 100);
- delay(1000);
- Serial.println("Motor stopped");
- digitalWrite(motor2Pin1, LOW);
- digitalWrite(motor2Pin2, LOW);
- delay(1000);
- Serial.println("Motor fwd 150");
- digitalWrite(motor2Pin1, HIGH);
- digitalWrite(motor2Pin2, LOW);
- ledcWrite(pwmChannel, 150);
- delay(1000);
- Serial.println("Motor stopped");
- digitalWrite(motor2Pin1, LOW);
- digitalWrite(motor2Pin2, LOW);
- delay(1000);
- /*
- while (dutyCycle <= 200){
- ledcWrite(pwmChannel, dutyCycle);
- Serial.print("Forward with duty cycle: ");
- Serial.println(dutyCycle);
- dutyCycle = dutyCycle + 5;
- delay(500);
- }
- dutyCycle = 200;
- */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement