K K / Mbed 2 deprecated Movement_code

Dependencies:   MODSERIAL QEI mbed

Revision:
1:17e250b48fe0
Parent:
0:e2de1fe5b34c
diff -r e2de1fe5b34c -r 17e250b48fe0 main.cpp
--- a/main.cpp	Mon Oct 05 21:00:15 2015 +0000
+++ b/main.cpp	Wed Oct 07 17:16:05 2015 +0000
@@ -8,59 +8,53 @@
 DigitalOut direction1(D7);
 PwmOut speed1(D6);
 DigitalIn button1(PTC6);
-
+DigitalOut led(LED_GREEN);
+DigitalOut led1(LED_RED);
+/*
+DigitalOut direction2(X1);//choose correct input
+PwmOut speed2(X2);//choose correct input
+DigitalIn button2(X3);//choose correct input
+*/
 int main()
 {
-   DigitalOut led(LED_RED);
    pc.baud(115200);
    float cycle = 0.6;//define the speed of the motor
    int motor1_on = 0;
    int motor1_dir=0;
-   int motor1_cw=0;
-   int motor1_ccw=1;
+   int button_toggle = 0;
+   int motor2_on = 0;
+   int motor2_dir = 0;
    
-   if (button1.read()==!motor1_on){//alternate between ccw and cw when the button is no longer being pressed.
-       motor1_dir=!motor1_dir;
-       }
-   while(button1.read() == motor1_on){// turn on motor 1 when the button is being pressed
-       DigitalOut led(LED_BLUE);
-       direction1.write(motor1_dir);//turn motor CCW or CW if set to 0
+ while(1){
+   led.write(1);
+   led1.write(1);
+   speed1.write(0);//write the speed to the motor  
+
+   //int button1_on = button1.read();
+   
+   while(button1.read() == motor1_on){
+       // turn on motor 1 when the button is being pressed
+       led.write(0);
+       direction1.write(motor1_dir);//turn motor CCW or CW
    //motor CW = 0
    //motor CCW = 1
-       speed1.period_us(100);//Set period of PWM to 100 us.
        speed1.write(cycle);//write the speed to the motor  
-}
-}
-       //determine speed of movement from the encoder signal
-       // the amount of counts for one revolution is 32
-       //this is X2 encodng, as the QEI uses X2 by default 
-       //and the motor encoder has a X4 encoder and thus 64 counts per revolution
-       //thus keeping in mind the gearbox with 1:131,25 gear ratio:
-       // the amount of counts for a gearbox revolution or resolution is 8400
-       // a revolution is 2 pi rad, resolution is : 8400/2 pi = 1336.90 counts/rad
-       //or for the encoder x2 its 668,45 counts/rad
- /*      
-   Rotational position in degrees can be calculated by:
- *
- * (pulse count / X * N) * 360
- *
- * Where X is the encoding type [e.g. X4 encoding => X=4], and N is the number
- * of pulses per revolution.
- *
- * Linear position can be calculated by:
- *
- * (pulse count / X * N) * (1 / PPI)
- *
- * Where X is encoding type [e.g. X4 encoding => X=44], N is the number of
- * pulses per revolution, and PPI is pulses per inch, or the equivalent for
- * any other unit of displacement. PPI can be calculated by taking the
- * circumference of the wheel or encoder disk and dividing it by the number
- * of pulses per revolution.
- 
-     * Reset the encoder.
-     *
-     * Sets the pulses and revolutions count to zero.
-     
-    void reset(void);
- */
+       }
+       while(1){
+       pc.printf("%d", button1.read());
+       wait(1);
+       }
+    }
+}/*
+   if (button2.read()==!motor2_on){//alternate between ccw and cw when the button is no longer being pressed.
+       motor2_dir=!motor2_dir;
+       }
+   while(button2.read() == motor2_on){// turn on motor 1 when the button is being pressed
+       DigitalOut led(LED_BLUE);
+       direction2.write(motor2_dir);//turn motor CCW or CW if set to 0
+   //motor CW = 0
+   //motor CCW = 1
+       speed2.period_us(100);//Set period of PWM to 100 us.
+       speed2.write(cycle);//write the speed to the motor  
+}*/
    
\ No newline at end of file