304 8. ATMEL AVR OPERATING PARAMETERS AND INTERFACING
8.12.5 MICROCONTROLLER CODE
In this example we use switch 2 (SW2 – D4) to control the left thruster (motor or bilge pump) and
switch 4 (SW4 D5) to control the right thruster motor. This is a simple on/off control. That is,
when a specific switch is asserted the motor will be on and the corresponding LED will illuminate.
//***********************************************************************
//digital input pins
#define left_switch 4 //digital pin - left switch
#define right_switch 5 //digital pin - right switch
//digital output pins
//LED indicators
#define left_LED 7 //digital pin - left LED
#define right_LED 9 //digital pin - right LED
//motor outputs
#define left_motor 11 //digital pin - left_motor
#define right_motor 10 //digital pin - right_motor
int left_sw_value, right_sw_value;
void setup()
{
//switch inputs
pinMode(left_switch, INPUT); //configure pin 4 for digital input
pinMode(right_switch,INPUT); //configure pin 5 for digital input
//LED indicators
pinMode(left_LED, OUTPUT); //configure pin 7 for digital output
pinMode(right_LED, OUTPUT); //configure pin 9 for digital output
//motor outputs - PWM
pinMode(left_motor, OUTPUT); //config pin 11 for digital output
pinMode(right_motor, OUTPUT); //config pin 10 for digital output
}
void loop()
{
//read input switches
left_sw_value = digitalRead(left_switch);

Get Arduino Microcontroller, 2nd Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.