Zlatan Čilić Lejla Agić

Dependencies:   TSI mbed

Revision:
0:5cb9ff1b9c43
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon May 12 07:06:58 2014 +0000
@@ -0,0 +1,111 @@
+#include "mbed.h"
+#include "TSISensor.h"
+#include <string>
+
+PwmOut crvena(LED1);
+PwmOut zelena(LED2);
+PwmOut plava(LED3);
+Serial pc(USBTX, USBRX);
+TSISensor tsi;
+Ticker tsiTicker;
+string buffer;
+bool citanjeTSI(false);
+
+
+void ocitajPC()
+{
+    while(pc.readable())
+    {
+        buffer.push_back(pc.getc());
+    }
+}
+
+void ispisiTSI()
+{
+        pc.printf("%f\n", tsi.readPercentage());
+}
+
+void ocitajIzvrsi()
+{
+        //ocitajPC();
+        
+        buffer.push_back(pc.getc());
+        if(buffer[0] == 'P')
+        {
+             tsiTicker.attach(&ispisiTSI, 1.0);
+             buffer = "";
+             return;
+             //pc.printf("\n");
+         }
+        if(buffer[0] == 'Z')
+        {
+             tsiTicker.detach();
+             buffer = "";
+             return;
+             // pc.printf("\n"); 
+        }
+        
+        if(buffer[0] == 'R' || buffer[0] == 'G' || buffer[0] == 'B')
+        {
+           buffer.push_back(pc.getc());
+           if(buffer[1] < '0' || buffer[1] > '9')
+           {
+                buffer = "";
+                return;
+            }
+            buffer.push_back(pc.getc());
+           if(buffer[2] < '0' || buffer[2] > '9')
+           {
+                buffer = "";
+                return;
+            }               
+            
+            float intenzitet(0);
+            intenzitet = ((buffer[1] - '0') * 0.1 + (buffer[2] - '0') * 0.01);
+            if(buffer[0] == 'R')
+            {
+                crvena = 1-intenzitet;
+                zelena = 1;
+                plava = 1;
+            }
+            else if(buffer[0] == 'G')
+            {
+                crvena = 1;
+                zelena = 1-intenzitet;
+                plava = 1;
+            }
+            else
+            {
+                crvena = 1;
+                zelena = 1;
+                plava = 1-intenzitet;
+            }   
+               
+               
+               
+               
+               buffer = "";
+                return;
+            }
+        
+        
+        
+        buffer = "";
+        
+        
+}
+
+
+
+
+ 
+int main() {
+    plava = 1;
+    crvena = 1;
+    zelena = 1;
+    while(1)
+    {
+        ocitajIzvrsi();
+    }
+       
+}
\ No newline at end of file