/* Program of DC motor control through Wytec EduBase/EduPad board. * The Wytec EduBase/EduPad board has a motor control device that consists of four * half-bridge circuit. This program uses two half-bridges to control the output * of M3-M4 terminals. A DC motor should be connected between M3 and M4 terminals * of the board. Pin 39 is used to control the pulse-width modulation of the output. * Pin 19 and 38 control the direction of the half-bridges and in turn control the * direction of the motor. * The program speeds up the motor, slows down the motor, reverse the direction then repeats. * * Energia 1.6.10E18 */ const int PWM34 = 39; const int HalfBridgeLeft = 19; const int HalfBridgeRight = 38; void setup() { pinMode(HalfBridgeRight, OUTPUT); pinMode(HalfBridgeLeft, OUTPUT); } void loop() { // change motor direction digitalWrite(HalfBridgeRight, HIGH); digitalWrite(HalfBridgeLeft, LOW); // ramp up the pulse width for(int pulseWidth = 0 ; pulseWidth <= 255; pulseWidth +=5) { analogWrite(PWM34, pulseWidth); // set pulse width delay(50); // pause before reverse } // ramp down the pulse width for(int pulseWidth = 255 ; pulseWidth >= 0; pulseWidth -=5) { analogWrite(PWM34, pulseWidth); // set pulse width delay(50); // pause before reverse } // change motor direction digitalWrite(HalfBridgeRight, LOW); digitalWrite(HalfBridgeLeft, HIGH); // ramp up the pulse width for(int pulseWidth = 0 ; pulseWidth <= 255; pulseWidth +=5) { analogWrite(PWM34, pulseWidth); // set pulse width delay(50); // pause before reverse } // ramp down the pulse width for(int pulseWidth = 255 ; pulseWidth >= 0; pulseWidth -=5) { analogWrite(PWM34, pulseWidth); // set pulse width delay(50); // pause before reverse } }