Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: MODSERIAL QEI mbed
Revision 11:be7660614c5c, committed 2015-10-15
- Comitter:
- Technical_Muffin
- Date:
- Thu Oct 15 21:20:23 2015 +0000
- Parent:
- 10:2dd707673b3b
- Child:
- 12:2d3d7a9ca496
- Commit message:
- untested motor revision
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Thu Oct 15 14:12:58 2015 +0000
+++ b/main.cpp Thu Oct 15 21:20:23 2015 +0000
@@ -18,11 +18,13 @@
int main()
{
- float cycle = 0.7f;//define the speed of the motor
+ float cycle = 0.7;//define the speed of the motor
bool motor1_on = 1;//set the on variable of motor 1
int motor1_dir=0;//set the direction of motor 1
bool motor2_on =1;//set the on variable of motor 2
int motor2_dir = 0;//set the direction of motor 1
+ int n1=1;
+ int n2=1;
while(1){
led3.write(0);
@@ -42,16 +44,22 @@
else if(button_toggle1 == 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);
- led1.write(0);
- speed1.write(cycle);//write the speed to the motor
- // pc.printf("%f",speed1.read());//klopt nog niet, maar voorlopig zorgt het uitlezen ervoor dat het werkt.
- direction1.write(motor1_dir);//turn motor CCW or CW
- wait_us(3000);
- //motor CW = 0
- //motor CCW = 1
- }
+
+ if(button1.read()==false){
+ while(n1 == 1){
+ speed1.write(cycle);
+ direction1.write(1);//turn motor CCW or CW
+ led3.write(1);
+ led1.write(0);
+ n1=0;
+ }
+ }
+ else if (button1.read() == true){
+ while(n1==0){
+ speed1.write(0);
+ n1=1;
+ }
+ }
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.
@@ -63,14 +71,23 @@
else if(button_toggle2 == 1 && motor2_dir == 0){
motor2_dir = 1;
}
- while(button2.read() != motor2_on){// turn on motor 2 when the button is being pressed
- led3.write(1);
- led2.write(0);
- speed2.write(cycle);//write the speed to the motor
- pc.printf("%f",speed2.read());//klopt nog niet, maar voorlopig zorgt het uitlezen ervoor dat het werkt.
- direction2.write(motor2_dir);//turn motor CCW or CW
+
//motor CW = 0
//motor CCW = 1
- }
+ if(button1.read()==false){
+ while(n2 == 1){
+ speed2.write(cycle);
+ direction2.write(1);//turn motor CCW or CW
+ led3.write(1);
+ led2.write(0);
+ n2=0;
+ }
+ }
+ else if (button1.read() == true){
+ while(n2==0){
+ speed1.write(0);
+ n2=1;
+ }
+ }
}
}
\ No newline at end of file