tau new ticker toevoegen.

Dependencies:   HIDScope MODSERIAL QEI mbed

Fork of Tau_new by V D

Files at this revision

API Documentation at this revision

Comitter:
vd
Date:
Thu Nov 02 08:44:58 2017 +0000
Parent:
3:48397c80d0e4
Commit message:
tau new ticker toevoegen

Changed in this revision

MODSERIAL.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 48397c80d0e4 -r e22508afc194 MODSERIAL.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MODSERIAL.lib	Thu Nov 02 08:44:58 2017 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/Sissors/code/MODSERIAL/#a3b2bc878529
diff -r 48397c80d0e4 -r e22508afc194 main.cpp
--- a/main.cpp	Wed Nov 01 14:13:48 2017 +0000
+++ b/main.cpp	Thu Nov 02 08:44:58 2017 +0000
@@ -2,6 +2,7 @@
 #include "HIDScope.h"
 #include "QEI.h"
 #include "iostream"
+#include "MODSERIAL.h"
 
 //Leds
 DigitalOut ledb(LED_BLUE);
@@ -18,68 +19,86 @@
 // HIDscope
 HIDScope scope(1);
 
+//Ticker
+Ticker tick;
+float f = 0.2;
+
 // Encoder
-//Ticker tick;
-float X = 32;
-float N = 131;
+float X = 32.0;
+float N = 131.0;
 float pulse_count;
 float angle_motor;
-QEI Encoder(A0,A1,NC,N);
-
-//Minimum wait time between rolls
-float t = 1;
+QEI Encoder(D8,D9,NC,N);
+MODSERIAL pc(USBTX,USBRX);
 
-// Encoder measurement function
-void Measure()
-{
-    // Get pulses and send to HIDScope
-    pulse_count = Encoder.getPulses();
-    
-    int angle_pp =360/(X * N);
-    
-   int angle = pulse_count*angle_pp;
-    
-    scope.set(0, angle);
-    scope.send();
-}
+//ticker function
 
-//Dice rolling function
-void Roll()
-{  
-    //motor1DC = 0;
-    
-    ledg = 1; // green led off
-    ledr = 0; // red led on = rolling
-    
-    motor1PWM = 1; // motor on -> roll dice
-    wait(3.0);
-    motor1PWM = 0; // motor off
+//void send(angle)
+//{ 
 
+//    scope.set(0, angle);
+//    scope.send();
+//}
 
-    //motor1DC = abs(motor1DC-1); // rotate other way next time
-    
-    //ledr = 1; // red led off
-    //ledb = 0; // blue led on
-    
-    //Encoder.reset();
-}
 
 int main()
 {
-    motor1DC = 0;
+
+    pc.baud(9600);
+    pc.printf("Hello world");
+    motor1DC = -1;
     ledb = 1;
     ledr = 1;
     ledg = 0;
-    
-    while (true) 
-    {
-        if(button1==0)
-        { 
-            Roll();
-            wait(t); // wait before next roll to protect motors
+
+    while (true) {
+
+        //angle=0;
+
+        if(button1==false) {
+            
+            
+            
+            wait(1.0); // wait before next roll to protect motors
+            //ledr = 1;
+            ledb = 1;
+            //ledg = 0; // green led on = ready to roll
+
+            ledg = 1; // green led off
+            ledr = 0; // red led on = rolling
+
+            motor1PWM = 1; // motor on
+            wait(3.00); //1.025
+            motor1PWM = 0; // motor off
+
+            wait(1.0);
+            ledr = 1;
             ledb = 1;
-            ledg = 0; // green led on = ready to roll
-        } 
-        Measure();     
+            ledg = 0;
+            // green led on = ready to roll
+
+            // Get pulses and send to HIDScope
+            pulse_count = Encoder.getPulses();
+
+            float angle_pp =360/(X * N);
+            float angle = pulse_count*angle_pp;
+
+            pc.printf(" pulse count: %f angle: %f \r \n ", pulse_count, angle);
+            
+            //tick.attach(&send(angle), f);
+
+            scope.set(0, angle);
+            scope.send();
+
+            Encoder.reset();
+            
+            
+        }
+
     }
-}
\ No newline at end of file
+
+
+
+}
+
+// screen /dev/tty.usbmodem1412 9600
\ No newline at end of file