8.12. EXTENDED EXAMPLE 4: SUBMERSIBLE ROBOT 305
right_sw_value = digitalRead(right_switch);
//left switch asserted - turn left by asserting right motor
if((left_sw_value==HIGH)&&(right_sw_value==LOW))
{
digitalWrite(left_LED, LOW); //turn left LED off
digitalWrite(left_motor, LOW); //turn left motor off
digitalWrite(right_LED, HIGH); //turn right LED on
digitalWrite(right_motor, HIGH); //turn right motor on
delay(500); //delay 500 ms
}
//right switch asserted - turn right by asserting left motor
if((left_sw_value==LOW)&&(right_sw_value==HIGH))
{
digitalWrite(left_LED, HIGH); //turn left LED on
digitalWrite(left_motor, HIGH); //turn left motor on
digitalWrite(right_LED, LOW); //turn right LED off
digitalWrite(right_motor, LOW); //turn right motor off
delay(500); //delay 500 ms
}
//both switches asserted - move ROV forward
if((left_sw_value==HIGH)&&(right_sw_value==HIGH))
{
digitalWrite(left_LED, HIGH); //turn left LED on
digitalWrite(left_motor, HIGH); //turn left motor on
digitalWrite(right_LED, HIGH); //turn right LED on
digitalWrite(right_motor, HIGH); //turn right motor on
delay(500); //delay 500 ms
}
}
//***********************************************************************
8.12.6 PROJECT EXTENSIONS
The control system provided above has a set of very basic features. Here are some possible extensions
for the system:
Provide adjustable speed control for each motor. This advanced feature requires several mod-
ifications including a proportional joystick and pulse width modulation signals to the motor.

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.