Brushed DC Motor Tutorial (อ้างอิง www.arduino-board.com/arduino/brushed-motor? )
Brushed DC Motor Tutorial


#define MTR_POS 10 #define MTR_NEG 11 void setup() { // Motor stopped. analogWrite(MTR_POS, 0); analogWrite(MTR_NEG, 0); } void loop() { int x; // Ramp the motor to full speed CW. for (x = 0; x < 255; ++x) { analogWrite(MTR_POS, x); delay(10); } // Ramp the motor to stop. for (x = 255; x > 0; --x) { analogWrite(MTR_POS, x); delay(10); } delay(500); // Ramp the motor to full speed CCW. for (x = 0; x < 255; ++x) { analogWrite(MTR_NEG, x); delay(10); } // Ramp the motor to stop. for (x = 255; x > 0; --x) { analogWrite(MTR_NEG, x); delay(10); } delay(500); }
What It Does
The motor starts out with 0, corresponding to 0 Volts, on both terminals. Every 10mS the program increases the voltage by increasing the pulse width on the positive terminal. When the positive terminal has 255, or 12V on it, the program then starts slowly decreasing the voltage back to zero. The effect of this is the motor speed, which starts at zero, is ramped up to full speed in 2.55 seconds, then back to stopped in another 2.55 seconds.
Then, after a half-second delay, the negative terminal is driven from zero up to 12V in 2.55 seconds. This ramps the motor speed up to full again, but this time in the opposite direction (counterclockwise). The program then ramps the speed down to a full stop, waits half of a second and repeats the whole process.
ความคิดเห็น
แสดงความคิดเห็น