Interrupt changes LED

Dependencies:   m3pi mbed

Fork of Test1 by Martin Ofalt Jr.

Files at this revision

API Documentation at this revision

Comitter:
wqz9822
Date:
Thu Oct 15 16:51:04 2015 +0000
Parent:
0:1da3cc3bc3a5
Commit message:
Interrupt changes LED

Changed in this revision

m3pi.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 1da3cc3bc3a5 -r 963bf6581114 m3pi.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/m3pi.lib	Thu Oct 15 16:51:04 2015 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/users/wqz9822/code/m3pi/#f1e6f60b2fdf
diff -r 1da3cc3bc3a5 -r 963bf6581114 main.cpp
--- a/main.cpp	Thu Dec 02 07:21:02 2010 +0000
+++ b/main.cpp	Thu Oct 15 16:51:04 2015 +0000
@@ -1,59 +1,108 @@
 #include "mbed.h"
+#include "m3pi.h"
 
-Serial transmit(p28,p27);
-Timer t;
+//Ticker toggler1;  // periodic interrupt routines
 InterruptIn risingEdge(p16);
 
+m3pi m3pi;
+Serial Wixel(p28, p27); // tx, rx
+AnalogIn analog (p20);
 DigitalOut myled(LED1);
-DigitalOut myled2(LED2);
+
+int behaviour;
+float inc;
+bool incCurve;
+bool sign = true;
+volatile int ledValue;
 
-long int count;
+void changeCurve()
+{
+    if (sign)
+    {
+        inc = 0.35;
+    }
+    else
+    {
+        inc = 0.45;
+    }
+    sign = !sign;
+}
 
-//Increment the counter variable
-void pulses() {
-    if(myled2 == 1) {
-        myled2 = 0;
-    } else {
-        myled2 = 1;
+//Generate series of circles with different radius
+void seriesOfCircle()
+{
+    if(incCurve)
+    {
+        inc += 0.001;
+    }
+    else
+    {
+        inc -= 0.001;        
     }
-    count++;
+    
+    if(inc >= 0.6){incCurve = false;}
+    if(inc <= 0.45){incCurve = true;}
+}
+
+void toggleLED()
+{
+
+    if (ledValue == 0)
+    {
+        ledValue = 1;
+    }
+    else
+    {
+        ledValue = 0;
+    }
+
+   myled = ledValue;
+   
+}
+
+unsigned int random_generator (void)
+{
+    unsigned int x = 0;
+    unsigned int iRandom = 0;
+ 
+    for (x = 0; x <= 32; x += 2)
+    {
+        iRandom += ((analog.read_u16() % 3) << x);
+        wait_us (10);
+    }
+    
+    return iRandom;
 }
 
 //main program
-int main() {
-
-    risingEdge.rise(&pulses);
-   
-    while(1) {
-       
-      //  myled = 0;
-        
-        t.reset();
-        t.start();
-        count = 0;
-        while(t.read_ms() < 400) {
-            ;
+int main() 
+{
+     
+    Wixel.baud(115200);
+    //srand (random_generator()); // Using ADC value to generate random seed
+    risingEdge.rise(&toggleLED);
+    ledValue = 0;
+    //toggler1.attach(&changeCurve,0.9);  // toggles curve every 900 ms
+    //inc = 0.45;
+    //incCurve = true;
+    while(1)  
+    {
+        //behaviour = rand() % 5 + 1;        
+        switch (behaviour)
+        {
+            case 1:
+                // This is for testing rose curve
+                //m3pi.left_motor(inc);
+                //wait(0.1);
+                //m3pi.right_motor(0.7);
+                //wait(0.1);
+                break;
+            case 2:
+            
+                break;
         }
+    }
        
-        t.stop();
-      //  myled = 1;
-        long int temp = count;
-       // lcdout.putc(0xFE);
-      //  lcdout.putc(0x01);
-      //  lcdout.printf("Count: %d\n", temp);
-     // transmit.printf("Count: %d", temp);
-        double rev = (double)temp/30.0;
-        double sec = 1000.0/(double)t.read_ms();
-        double rps = rev * sec;
-        double rpm = rps*60.0;
-        int irpm = (int)rpm;
-        
-        //lcdout.printf("Speed: %0.2f RPM", rpm);
-      //  transmit.printf(" Speed: %0.2f RPM", rpm);
-      transmit.printf("%d", irpm);
-      //  transmit.putc(0xA);
-        transmit.putc(0xD);
-    }
 }