The C sketch for running the DC motor using a push button is provided in the following. The sketch is designed to run the motor for 1 second and then stop it every time the push button is pressed.
The code in this chapter may be freely downloaded from the location for this chapter mentioned in Chapter 1, Boot Camp.
The following code is a basic DC motor sketch:
//**********************************************************/
// Step-1: CONFIGURE VARIABLES
//**********************************************************/
int motorPin = 3; //this is a PWM capable pin
int buttonPin = 8;
int buttonState = LOW;
//**********************************************************/
// Step-2: INITIALIZE I/O PARAMETERS
//**********************************************************/
void setup()
{
pinMode(motorPin, OUTPUT);
pinMode(buttonPin, INPUT);
}
//*************...