The width of the pulses are varied to control the motor speed, pulses with a narrow width will cause the motor to spin quite slowly. With PWM the motor is sent a series of pulses. It can be done with help of Pulse Width Modulation ( PWM). Changing the speed however is a different story. To reverse the direction in which the DC motor rotates you simply reverse the polarity of the DC current that you apply to it. To move Motor 1 forward we use following command:ĭigitalWrite(In1, HIGH) digitalWrite(In2, LOW) Īnd to reverse Motor 1 we just change pins values:ĭigitalWrite(In1, LOW) digitalWrite(In2, HIGH) Next, to perform some motor action, we use digitalWrite(pin, value) to write a HIGH or a LOW value to a digital pin. But its a not a dogma you can assign your own variable names which is most suit you. To eliminate some confusion - all pins have the same names as in L298N Motor Controller Board. PinMode(In1,OUTPUT) // set control pin 1 as OUTPUT We will first define a I/O pins as an output in void setup() using the following function: PinMode(pin, mode) - Configures the specified pin to behave either as an input or an output. The compiler will replace references to these constants with the defined value at compile time. Defined constants in Arduino don’t take up any program memory space on the chip. #define is a useful C++ component that allows the programmer to give a name to a constant value before the program is compiled. # define - before void setup(), we use #define statements to create fixed variables.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |