Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 #include "mbed.h" 00002 #include "TSISensor.h" 00003 00004 #define LED_ON 0 00005 #define LED_OFF 1 00006 #define RGB_COMPONENTS 3 00007 #define RGB_COLORS ((int) pow(2 *1.0, RGB_COMPONENTS *1.0)) 00008 #define BAUDRATE 115200 00009 #define MAXDELAY 0.3 00010 #define UART_INTERVAL 0.2 00011 00012 float sliderNewValue; // temp data of touch slider 00013 float mainLoopDuration; // main loop measurement 00014 float delay = MAXDELAY; // blink delay 00015 Serial pc(USBTX, USBRX); // UART 00016 00017 void debugOutput() 00018 { 00019 if (sliderNewValue > 0) 00020 { 00021 // UART output 00022 pc.printf("slider input = %3.0f%% --> ", 100.0 * sliderNewValue); 00023 pc.printf("blink delay = %3.0f ms", 1000 * delay); 00024 pc.printf(" (last main loop took %4.0f ms)\n", mainLoopDuration); 00025 } 00026 } 00027 00028 int main() 00029 { 00030 // RGB LED 00031 DigitalOut led_rgb_red(LED1); // red 00032 DigitalOut led_rgb_grn(LED2); // green 00033 DigitalOut led_rgb_blu(LED3); // blue 00034 DigitalOut led_rgb[RGB_COMPONENTS] = {led_rgb_red, led_rgb_grn, led_rgb_blu}; 00035 00036 // Touch slider 00037 TSISensor tsi; 00038 00039 // UART 00040 pc.baud(BAUDRATE); 00041 00042 // ticker for debugOutput() 00043 Ticker ticker1; 00044 ticker1.attach(&debugOutput, UART_INTERVAL); 00045 00046 // timer for main loop measurement 00047 Timer timer1; 00048 00049 // main loop 00050 while (true) 00051 { 00052 timer1.start(); 00053 00054 // show all colors 00055 for (int i=1; i<RGB_COLORS; i++, wait(delay)) // for each possible color 00056 { 00057 for (int j=0; j<RGB_COMPONENTS; j++) // for each LED component 00058 led_rgb[j] = ( i & 1<<j ) ? LED_ON : LED_OFF; // set LED component according to active color 00059 00060 // check for active slider input 00061 if ( (sliderNewValue = tsi.readPercentage()) > 0) 00062 { 00063 // set delay to slider input 00064 delay = MAXDELAY * sliderNewValue; 00065 } 00066 } 00067 00068 timer1.stop(); 00069 mainLoopDuration = timer1.read_ms(); 00070 timer1.reset(); 00071 } 00072 }
Generated on Wed Jul 13 2022 16:01:46 by
1.7.2