First pass test/example code

Dependencies:   TSI mbed

Files at this revision

API Documentation at this revision

Comitter:
hughesdt
Date:
Thu Apr 24 15:31:13 2014 +0000
Commit message:
Test/Example code for calculating Pi to 892 digits. Use timer to time the calculation. Serial to output to a terminal. And ticks to change the RGB LED color. Also commented out TSIsensor code to change the brightness of the LED

Changed in this revision

TSI.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
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r d46c7e391377 TSI.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TSI.lib	Thu Apr 24 15:31:13 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/vsluiter/code/TSI/#4dc2f5a3a731
diff -r 000000000000 -r d46c7e391377 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Apr 24 15:31:13 2014 +0000
@@ -0,0 +1,92 @@
+#include "mbed.h"
+#include "TSISensor.h"
+
+//DigitalOut myled(LED_BLUE);
+Serial pc(USBTX, USBRX);
+//PwmOut led(LED_GREEN);
+//TSISensor tsi;
+PwmOut r (LED_RED);
+PwmOut g (LED_GREEN);
+PwmOut b (LED_BLUE);
+Ticker tick;
+Timer t;
+
+#define  n    1000//1125
+#define  len  10*n/3
+void colorswing(void);
+int main() 
+{
+    int   i, j, k, q, x, nines, predigit,digits,total;
+    int  a[len];
+    
+    r.period(0.0001);
+    g.period(0.0001);
+    b.period(0.0001);
+    
+    tick.attach(&colorswing, 0.01);
+    
+    pc.baud(115200);
+    pc.printf("\nStart Pi Generator!\n");
+    total=0;
+    while(1)
+    {
+        //myled = !myled;
+        t.start();
+        digits=0;
+        for (j=1;j<=len;j++)
+            a[j] = 2;      
+        nines = 0;
+        predigit = 0;//               {First predigit is a 0}
+        for (j=1;j<=n;j++)
+        {
+            q = 0;
+            for(i=len;i>0;i--)
+            {
+                x    = 10*a[i] + q*i;
+                a[i] = x % (2*i - 1);
+                q    = x / (2*i - 1);
+                
+            }
+            a[1] = q % 10;
+            q = q / 10;
+            if (q == 9)
+            {    nines++;}
+            else
+            {    if (q == 10)
+                {
+                    pc.printf("%d",predigit+1);
+                    for (k=1;k<=nines;k++)// to nines do
+                        pc.printf("0");//            {zeros}
+                    predigit = 0;
+                    nines = 0;
+                }
+                else
+                {
+                    pc.printf("%d",predigit);
+                    predigit = q;
+                    if (nines != 0)// then
+                    {
+                        for(k=1;k<=nines;k++)// do
+                            pc.printf("9");
+                        nines = 0;
+                    }
+                }
+                digits++;digits+=nines;
+                
+            }
+        }t.stop();
+        pc.printf("%d\r\nDigits=%d\r\nTotal=%d\r\nTimerRequired=%fsec\r\n",predigit,digits,++total,t.read());
+        //led = 1.0 - tsi.readPercentage();
+        t.reset();
+    }
+}
+
+void colorswing()
+{
+    static float p=0;
+    p += 0.003;
+    if(p>3)p=0;
+    r = 1.0 - ((p < 1.0) ? 1.0 - p : (p > 2.0) ? p - 2.0 : 0.0);
+    g = 1.0 - ((p < 1.0) ? p : (p > 2.0) ? 0.0 : 2.0 - p);
+    b = 1.0 - ((p < 1.0) ? 0.0 : (p > 2.0) ? 3.0 - p : p - 1.0);        
+}
\ No newline at end of file
diff -r 000000000000 -r d46c7e391377 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Apr 24 15:31:13 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/6473597d706e
\ No newline at end of file