code for basic movement of robot
Dependencies: MODSERIAL QEI mbed
Diff: main.cpp
- Revision:
- 13:6cea4a9fcf7a
- Parent:
- 12:2d3d7a9ca496
- Child:
- 14:41d069cf4701
--- a/main.cpp Fri Oct 16 09:51:14 2015 +0000 +++ b/main.cpp Fri Oct 23 09:40:45 2015 +0000 @@ -34,8 +34,8 @@ led2.write(1); pc.baud(115200); - int diffa1 = button1.read();//read out the button 1 signal and calculate if it is being pressed or released - wait(0.2);//from this we can determine if the rotation direction needs to be reversed. + int diffa1 = -button1.read();//read out the button 1 signal and calculate if it is being pressed or released interrupt function might work better as toggle + wait(0.3);//from this we can determine if the rotation direction needs to be reversed. int diffb1 = button1.read(); int button_toggle1 = diffa1-diffb1; if(button_toggle1 == 1 && motor1_dir == CW){ @@ -63,7 +63,7 @@ } int diffa2 = button2.read();//read out the button 2 signal and calculate if it is being pressed or released - wait(0.2);//from this we can determine if the rotation direction needs to be reversed. + wait(0.3);//from this we can determine if the rotation direction needs to be reversed. int diffb2 = button2.read(); int button_toggle2 = diffa2-diffb2; if(button_toggle2 == 1 && motor2_dir == CW){ @@ -80,7 +80,7 @@ led2.write(0); while(n2 == 1){ speed2.write(cycle);//write speed only on first run through the loop - direction2.write(1);//turn motor CCW or CW + direction2.write(motor2_dir);//turn motor CCW or CW n2=0; }