code for basic movement of robot
Dependencies: MODSERIAL QEI mbed
Diff: main.cpp
- Revision:
- 7:46d9f01afba2
- Parent:
- 6:206fff3b20b0
- Child:
- 8:e0fc6dd187a2
--- a/main.cpp Fri Oct 09 09:33:24 2015 +0000 +++ b/main.cpp Fri Oct 09 10:00:30 2015 +0000 @@ -14,7 +14,7 @@ int main() { - float cycle = 0.6f;//define the speed of the motor + float cycle = 0.7f;//define the speed of the motor bool motor1_on = 1; int motor1_dir=0; @@ -24,6 +24,16 @@ led2.write(1); speed1.write(0); pc.baud(115200); + int diffa = button1.read(); + wait(0.2); + int diffb = button1.read(); + int button_toggle = diffa-diffb; + if(button_toggle == 1 && motor1_dir == 1){ + motor1_dir = 0; + } + else if(button_toggle == 1 && motor1_dir == 0){ + motor1_dir = 1; + } while(button1.read() != motor1_on){// turn on motor 1 when the button is being pressed led3.write(1); @@ -35,19 +45,7 @@ //motor CW = 0 //motor CCW = 1 } - pc.printf("toggle on or off %d \n ", button1.read()); - int diffa = button1.read(); - wait(0.2); - int diffb = button1.read(); - int button_toggle = diffa-diffb; - if(button_toggle == 1 && led1.read() ==1){ - led1.write(0); - led2.write(1); - } - else if(button_toggle == 1 && led2.read() == 1){ - led1.write(1); - led2.write(0); - } + } }