UNAL_Procesadores Actividad 2

Dependencies:   mbed TSI

Files at this revision

API Documentation at this revision

Comitter:
contechno
Date:
Wed Oct 09 17:20:23 2019 +0000
Commit message:
UNAL_Procesadores; Actividad 2

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 6759fffc4e2b TSI.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TSI.lib	Wed Oct 09 17:20:23 2019 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/emilmont/code/TSI/#507b1f67804b
diff -r 000000000000 -r 6759fffc4e2b main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Oct 09 17:20:23 2019 +0000
@@ -0,0 +1,47 @@
+// UNAL - Procesadores
+// Actividades Oct/2019 - JMP
+
+#include "mbed.h"
+#include "TSISensor.h" // Slider-Sensor
+
+#define POLLTIME 0.1 // Time in ms, how often the Touch-Sensor is read out
+
+void toggleWhite(); // Prototype for toggle-function
+
+DigitalOut red(LED1); //red
+DigitalOut green(LED2); //Green
+DigitalOut blue(LED3); //Blue
+
+Serial pc(USBTX, USBRX); // Init serial
+
+int main() {
+    TSISensor touchSensor; // Init TSISensor-struct
+    int pollCtr = 0;
+    int tmpSliderPerc = 0;
+    
+    // Reset all LEDs to off (LEDs are low-active)
+    red = 1;
+    green = 1;
+    blue = 1;
+    
+    while(1) {
+        if(pollCtr >= (1/POLLTIME)) { // Toggle LED after 1s (every "1/POLLTIME"-loops)
+            toggleWhite(); // Call function which toggles LED
+            pollCtr = 0; // Reset counter
+        }
+        
+        if((tmpSliderPerc < (int)(touchSensor.readPercentage()*100.0) - 3) || (tmpSliderPerc > (int)(touchSensor.readPercentage()*100.0) + 3)) { // If the Slider-Value has changed while "noise" (+/- 3%) is ignored, print actual value
+            tmpSliderPerc = (int)(touchSensor.readPercentage()*100.0);
+            pc.printf("Touchsensor: %d%%\r\n",tmpSliderPerc);
+        }
+        
+        wait(POLLTIME);
+        pollCtr++;
+    }
+}
+
+void toggleWhite() { // Functions toggles all three RGB-LEDs (white light on/off)
+        red = !red;
+        blue = !blue;
+        green = !green;
+}
\ No newline at end of file
diff -r 000000000000 -r 6759fffc4e2b mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Oct 09 17:20:23 2019 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
\ No newline at end of file