Advertisement
Guest User

Arduino, free to use ( Arduino shield )

a guest
Jun 2nd, 2015
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.78 KB | None | 0 0
  1. const int
  2. PWM_A   = 3,
  3. DIR_A   = 12,
  4. BRAKE_A = 9,
  5. SNS_A   = A0;
  6.  
  7.  
  8. void setup() {
  9.  
  10.   // Configure the A output
  11.   pinMode(BRAKE_A, OUTPUT);  // Brake pin on channel A
  12.   pinMode(DIR_A, OUTPUT);    // Direction pin on channel A
  13.  
  14.   // Open Serial communication
  15.   Serial.begin(300);
  16.   Serial.println("Motor shield DC motor Test:\n");
  17. }
  18.  
  19. void loop() {
  20.  
  21.  
  22. // Set the outputs to run the motor forward
  23.  
  24.   Serial.println("Forward");
  25.   digitalWrite(BRAKE_A, LOW);  // setting againg the brake LOW to disable motor brake
  26.   digitalWrite(DIR_A, LOW);    // now change the direction to backward setting LOW the DIR_A pin
  27.  
  28.   analogWrite(PWM_A, 150);     // Set the speed of the motor
  29.  
  30.   delay(3500);
  31.   Serial.print("current consumption forward: ");
  32.   Serial.println(analogRead(SNS_A));
  33.  
  34.   // now stop the motor by inertia, the motor will stop slower than with the brake function
  35.   analogWrite(PWM_A, 0);       // turn off power to the motor
  36.  
  37.   Serial.print("current brake: ");
  38.   Serial.println(analogRead(A0));
  39.   Serial.println("End of the motor shield test with DC motors. Thank you!");
  40.  
  41.  
  42. // Set the outputs to run the motor backward
  43.  
  44.   digitalWrite(BRAKE_A, LOW);  // setting brake LOW disable motor brake
  45.   digitalWrite(DIR_A, HIGH);   // setting direction to HIGH the motor will spin backward
  46.  
  47.   analogWrite(PWM_A, 150);     // Set the speed of the motor, Value can be from 0-255
  48.  
  49.   delay(700);                 // hold the motor at full speed for X milliseconds
  50.   Serial.print("current consumption backwards: ");
  51.   Serial.println(analogRead(SNS_A));
  52.  
  53. // Brake the motor
  54.  
  55.   Serial.println("Start braking\n");
  56.   // raising the brake pin the motor will stop faster than the stop by inertia
  57.   digitalWrite(BRAKE_A, HIGH);  // raise the brake
  58.   delay(600);
  59.  
  60.   while(1);
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement