Tom Kelliher
/
Interrupts
Starting point code for CS 220 Lab 5.
Fork of FRDM_TSI by
Revision 6:1096b1fd8d0a, committed 2017-06-26
- Comitter:
- tpkelliher
- Date:
- Mon Jun 26 16:05:16 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 1096b1fd8d0a main.cpp --- a/main.cpp Thu May 09 09:26:46 2013 +0000 +++ b/main.cpp Mon Jun 26 16:05:16 2017 +0000 @@ -1,12 +1,57 @@ #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. +DigitalIn button(PTA1); +TSISensor tsi; + +// The serial connection is available, if necessary, for debugging purposes. +Serial pc(USBTX,USBRX); + + +// Function prototype. +void cpuIntensive(); + + +int main(void) +{ + button.mode(PullUp); + redLed = greenLed = blueLed = LED_OFF; + + while (1) { + cpuIntensive(); + + // Use the touch sensor to scale the green LED's brightness + // to be between LED_ON and LED_OFF. + greenLed = LED_ON + (LED_OFF - LED_ON) * (1.0 - tsi.readPercentage()); + + if (button) + blueLed = LED_OFF; + else + blueLed = LED_ON; } +} + + +// 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 1096b1fd8d0a mbed.bld --- a/mbed.bld Thu May 09 09:26:46 2013 +0000 +++ b/mbed.bld Mon Jun 26 16:05:16 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