Tom Kelliher
/
Interrupts
Starting point code for CS 220 Lab 5.
Fork of FRDM_TSI by
main.cpp
- Committer:
- tpkelliher
- Date:
- 2017-06-26
- Revision:
- 6:1096b1fd8d0a
- Parent:
- 1:51b1b688179a
File content as of revision 6:1096b1fd8d0a:
#include "mbed.h" #include "TSISensor.h" #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); }