Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const int
- PWM_A = 3,
- DIR_A = 12,
- BRAKE_A = 9,
- SNS_A = A0;
- void setup() {
- // Configure the A output
- pinMode(BRAKE_A, OUTPUT); // Brake pin on channel A
- pinMode(DIR_A, OUTPUT); // Direction pin on channel A
- // Open Serial communication
- Serial.begin(300);
- Serial.println("Motor shield DC motor Test:\n");
- }
- void loop() {
- // Set the outputs to run the motor forward
- Serial.println("Forward");
- digitalWrite(BRAKE_A, LOW); // setting againg the brake LOW to disable motor brake
- digitalWrite(DIR_A, LOW); // now change the direction to backward setting LOW the DIR_A pin
- analogWrite(PWM_A, 150); // Set the speed of the motor
- delay(3500);
- Serial.print("current consumption forward: ");
- Serial.println(analogRead(SNS_A));
- // now stop the motor by inertia, the motor will stop slower than with the brake function
- analogWrite(PWM_A, 0); // turn off power to the motor
- Serial.print("current brake: ");
- Serial.println(analogRead(A0));
- Serial.println("End of the motor shield test with DC motors. Thank you!");
- // Set the outputs to run the motor backward
- digitalWrite(BRAKE_A, LOW); // setting brake LOW disable motor brake
- digitalWrite(DIR_A, HIGH); // setting direction to HIGH the motor will spin backward
- analogWrite(PWM_A, 150); // Set the speed of the motor, Value can be from 0-255
- delay(700); // hold the motor at full speed for X milliseconds
- Serial.print("current consumption backwards: ");
- Serial.println(analogRead(SNS_A));
- // Brake the motor
- Serial.println("Start braking\n");
- // raising the brake pin the motor will stop faster than the stop by inertia
- digitalWrite(BRAKE_A, HIGH); // raise the brake
- delay(600);
- while(1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement