Solution to CS 220 Lab 5.

Dependencies:   TSI mbed

Fork of FRDM_TSI by mbed official

Files at this revision

API Documentation at this revision

Comitter:
tpkelliher
Date:
Mon Jun 26 16:06:57 2017 +0000
Parent:
5:b44f5f02b879
Commit message:
Initial commit.

Changed in this revision

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 b44f5f02b879 -r 47f9dc2e7bdb main.cpp
--- a/main.cpp	Thu May 09 09:26:46 2013 +0000
+++ b/main.cpp	Mon Jun 26 16:06:57 2017 +0000
@@ -1,12 +1,70 @@
 #include "mbed.h"
 #include "TSISensor.h"
 
-int main(void) {
-    PwmOut led(LED_GREEN);
-    TSISensor tsi;
-    
-    while (true) {
-        led = 1.0 - tsi.readPercentage();
-        wait(0.1);
+
+#define LED_OFF 1.0
+// Using pulse width modulation, the closer this value is to 0.0, the
+// brighter the LED will be.
+#define LED_ON 0.9
+
+
+// Use pulse width modulation to decrease the LED's brightness.
+PwmOut greenLed(LED_GREEN);
+PwmOut redLed(LED_RED);
+PwmOut blueLed(LED_BLUE);
+
+// The blue LED is controlled by the button.
+// The green LED is controlled by the KL25Z's touch sensor.
+// The red LED is controlled by the cpuIntensive() function.
+InterruptIn button(PTA1);
+TSISensor tsi;
+Ticker flipper;
+
+// The serial connection is available, if necessary, for debugging purposes.
+Serial pc(USBTX,USBRX);
+
+
+// Function prototype.
+void cpuIntensive();
+
+
+void flip()
+{
+    greenLed = LED_ON + (LED_OFF - LED_ON) * (1.0 - tsi.readPercentage());
+}
+
+
+void rise()
+{
+    blueLed = LED_OFF;
+}
+
+
+void fall()
+{
+    blueLed = LED_ON;
+}
+
+
+int main(void)
+{
+    button.mode(PullUp);
+    flipper.attach(flip, 0.1);
+    button.rise(rise);
+    button.fall(fall);
+    redLed = greenLed = blueLed = LED_OFF;
+
+    while (1) {
+        cpuIntensive();
     }
+}
+
+
+// Using the long wait()s, simulate a CPU-intensive process.
+void cpuIntensive()
+{
+    redLed = LED_ON;
+    wait(2.0);
+    redLed = LED_OFF;
+    wait(3.0);
 }
\ No newline at end of file
diff -r b44f5f02b879 -r 47f9dc2e7bdb mbed.bld
--- a/mbed.bld	Thu May 09 09:26:46 2013 +0000
+++ b/mbed.bld	Mon Jun 26 16:06:57 2017 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/b3110cd2dd17
\ No newline at end of file
+https://mbed.org/users/mbed_official/code/mbed/builds/64910690c574
\ No newline at end of file