Elma Gazetic Nadin Hasanic

Dependencies:   TSI mbed

Files at this revision

API Documentation at this revision

Comitter:
tim004
Date:
Mon May 05 08:52:20 2014 +0000
Commit message:
LV8_PAI_TIM004_Zadatak_1

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 9e046233a0c4 TSI.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TSI.lib	Mon May 05 08:52:20 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/vsluiter/code/TSI/#4dc2f5a3a731
diff -r 000000000000 -r 9e046233a0c4 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon May 05 08:52:20 2014 +0000
@@ -0,0 +1,73 @@
+#include "mbed.h"
+#include "TSISensor.h"
+
+#include <string>
+
+Serial pc(USBTX, USBRX);
+PwmOut red(LED_RED), green(LED_GREEN),blue(LED_BLUE);
+
+TSISensor tsi;
+
+Ticker status;
+
+string rijec = "";
+bool mjerenje = false;
+
+bool is_digit(char c) {
+    return c >= '0' && c <= '9';
+}
+
+
+
+void show_status() {
+    if(mjerenje)
+        pc.printf("%f\n", tsi.readPercentage());
+        
+        if(rijec.length() == 1 && rijec[0] == 'P') {
+            mjerenje = true;
+        } else if(rijec.length() == 1 && rijec[0] == 'Z') {
+            mjerenje = false;
+        }
+}
+
+int main() {
+    
+    red = 1.;
+    green = 1.;
+    blue = 1.;
+    status.attach(show_status, 1.);
+    
+    while(true) {
+        rijec.push_back(pc.getc());
+        if(rijec.length() == 3) {
+            if(!is_digit(rijec[1]) || !is_digit(rijec[2]))
+                rijec="";
+            float intenzitet = ((rijec[2] - '0') + 10 * (rijec[1] - '0')) / 100.;
+            switch(rijec[0]) {
+                case 'R':
+                    red = 1 - intenzitet;
+                    rijec = "";
+                break;
+
+                case 'G':
+                    green = 1 - intenzitet;
+                    rijec = "";
+                break;
+
+                case 'B':
+                    blue = 1 - intenzitet;
+                    rijec = "";
+                break;
+
+                default:
+                    rijec="";
+            }
+        } else if(rijec.length() == 1 && rijec[0] == 'P') {
+            mjerenje = true;
+        } else if(rijec.length() == 1 && rijec[0] == 'Z') {
+            mjerenje = false;
+        }
+    }
+
+    return 0; 
+}
\ No newline at end of file
diff -r 000000000000 -r 9e046233a0c4 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon May 05 08:52:20 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/8a40adfe8776
\ No newline at end of file