.

Dependencies:   Servo mbed

Revision:
3:7eaf505f811e
Parent:
2:30ebae0d3e17
Child:
4:263bddc51c0f
--- a/main.cpp	Fri Feb 27 00:53:21 2015 +0000
+++ b/main.cpp	Fri Feb 27 02:18:17 2015 +0000
@@ -4,18 +4,12 @@
 PwmOut servo(PTA5);
 PwmOut motor(PTA4);
 Serial pc(USBTX, USBRX); // tx, rx
-DigitalIn din(PTA13);
+
+// encoder setup and variables
+InterruptIn interrupt(PTA13);
+int previous_val = -1;
 Timer t;
 
-void motor_sweep() {
-    for(float p = 0.0; p<.0025; p+=.0001){
-        motor.pulsewidth(p);
-        if(p == 0.0 || p == 1.0 || p == .0007){
-            wait(2);
-        }
-        wait(.1);
-    }
-}
 
 void servo_sweep(){
     for(float p = 0.001; p<0.002; p+=0.0001){
@@ -23,15 +17,23 @@
             wait(0.5);
     }
 }
-
+void fallInterrupt(){
+    pc.printf("fall");
+}
+void riseInterrupt(){
+    pc.printf("rise");
+}
+    
 int main() {
     servo.period(0.005);
     motor.period(.0025);
-    int previous_val = -1;
+    interrupt.fall(&fallInterrupt);
+    interrupt.rise(&riseInterrupt);
+    
     
     t.start();
     int lastchange = 0;
-    while(1){
+    while(1){/*
         if(din) {
             if(previous_val != 1){
                 int current_time = t.read_ms();
@@ -53,7 +55,8 @@
             myled = 0;
             //pc.printf("light");
         }
-        wait(.2f);
+        //wait(.2f);
+        */
         
         char choice = pc.getc();
         pc.putc(choice);
@@ -79,7 +82,7 @@
                 pc.printf("default\n\r");
                 break;
         }
-        
+    
        //servo_sweep();
        //motor_sweep();
        //motor.pulsewidth(.0025);