Using the cap slider and segment LCD on LG/WG/GG.
Dependencies: EFM32_CapSenseSlider EFM32_SegmentLCD mbed
Demo program showing the capacitive slider and segment LCD functionality of the Leopard, Wonder and Giant Gecko Starter Kits.
Information
All examples in this repo are considered EXPERIMENTAL QUALITY, meaning this code has been created as one-off proof-of-concept and is suitable as a demonstration for experimental purposes only. This code will not be regularly maintained by Silicon Labs and there is no guarantee that these projects will work across all environments, SDK versions and hardware.
main.cpp@6:c392ed815942, 2015-05-13 (annotated)
- Committer:
- stevew817
- Date:
- Wed May 13 13:55:50 2015 +0000
- Revision:
- 6:c392ed815942
- Parent:
- 4:4bd20d989554
- Child:
- 7:1e0a14ce9ca1
commit fix for combining sleep() and synchronous I/O
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
stevew817 | 0:9d3739ba3237 | 1 | #include "EFM32_SegmentLCD.h" |
stevew817 | 0:9d3739ba3237 | 2 | #include "EFM32_CapSenseSlider.h" |
stevew817 | 0:9d3739ba3237 | 3 | |
stevew817 | 0:9d3739ba3237 | 4 | /******************** Define I/O *****************************/ |
stevew817 | 0:9d3739ba3237 | 5 | InterruptIn in(PB9); |
stevew817 | 0:9d3739ba3237 | 6 | |
stevew817 | 0:9d3739ba3237 | 7 | silabs::EFM32_SegmentLCD segmentDisplay; |
stevew817 | 0:9d3739ba3237 | 8 | silabs::EFM32_CapSenseSlider capSlider; |
stevew817 | 0:9d3739ba3237 | 9 | |
stevew817 | 0:9d3739ba3237 | 10 | /******************** Define Timers *****************************/ |
stevew817 | 0:9d3739ba3237 | 11 | LowPowerTicker refreshTicker; |
stevew817 | 0:9d3739ba3237 | 12 | |
stevew817 | 0:9d3739ba3237 | 13 | /***************** Define global variables **********************/ |
stevew817 | 0:9d3739ba3237 | 14 | #define INIT_SECONDS 17600 |
stevew817 | 0:9d3739ba3237 | 15 | #define TEST_DURATION 10 |
stevew817 | 0:9d3739ba3237 | 16 | |
stevew817 | 0:9d3739ba3237 | 17 | volatile uint32_t count = 0, seconds = INIT_SECONDS; |
stevew817 | 0:9d3739ba3237 | 18 | |
stevew817 | 0:9d3739ba3237 | 19 | |
stevew817 | 0:9d3739ba3237 | 20 | /***************** Define callback handlers *********************/ |
stevew817 | 0:9d3739ba3237 | 21 | void tickerCallback(void); |
stevew817 | 0:9d3739ba3237 | 22 | void in_handler(); |
stevew817 | 0:9d3739ba3237 | 23 | void touchCallback(void); |
stevew817 | 0:9d3739ba3237 | 24 | void slideCallback(void); |
stevew817 | 0:9d3739ba3237 | 25 | |
stevew817 | 0:9d3739ba3237 | 26 | /** |
stevew817 | 0:9d3739ba3237 | 27 | * Callback for pushbutton interrupt |
stevew817 | 0:9d3739ba3237 | 28 | */ |
stevew817 | 0:9d3739ba3237 | 29 | void in_handler() { |
stevew817 | 0:9d3739ba3237 | 30 | count++; |
stevew817 | 0:9d3739ba3237 | 31 | segmentDisplay.ARing(count & 0x7, (count & 0x8) == 0); |
stevew817 | 0:9d3739ba3237 | 32 | } |
stevew817 | 0:9d3739ba3237 | 33 | |
stevew817 | 0:9d3739ba3237 | 34 | /** |
stevew817 | 0:9d3739ba3237 | 35 | * Callback for 1 second timebase |
stevew817 | 0:9d3739ba3237 | 36 | */ |
stevew817 | 0:9d3739ba3237 | 37 | void tickerCallback(void) { |
stevew817 | 0:9d3739ba3237 | 38 | seconds++; |
stevew817 | 0:9d3739ba3237 | 39 | uint32_t clockValue = ((seconds / 60) % 60) * 100 + (seconds % 60); |
stevew817 | 0:9d3739ba3237 | 40 | segmentDisplay.Number(clockValue); |
stevew817 | 0:9d3739ba3237 | 41 | segmentDisplay.Symbol(LCD_SYMBOL_COL10, seconds & 0x1); |
stevew817 | 0:9d3739ba3237 | 42 | } |
stevew817 | 0:9d3739ba3237 | 43 | |
stevew817 | 0:9d3739ba3237 | 44 | /** |
stevew817 | 0:9d3739ba3237 | 45 | * Callback for touching/untouching the cap slider |
stevew817 | 0:9d3739ba3237 | 46 | */ |
stevew817 | 0:9d3739ba3237 | 47 | void touchCallback(void) { |
stevew817 | 0:9d3739ba3237 | 48 | segmentDisplay.Symbol(LCD_SYMBOL_EFM32, capSlider.isTouched()); |
stevew817 | 0:9d3739ba3237 | 49 | |
stevew817 | 0:9d3739ba3237 | 50 | if(!capSlider.isTouched()) { |
stevew817 | 0:9d3739ba3237 | 51 | segmentDisplay.Write("Hello"); |
stevew817 | 0:9d3739ba3237 | 52 | } |
stevew817 | 0:9d3739ba3237 | 53 | } |
stevew817 | 0:9d3739ba3237 | 54 | |
stevew817 | 0:9d3739ba3237 | 55 | /** |
stevew817 | 0:9d3739ba3237 | 56 | * Callback for sliding the cap slider |
stevew817 | 0:9d3739ba3237 | 57 | */ |
stevew817 | 0:9d3739ba3237 | 58 | void slideCallback(void) { |
stevew817 | 0:9d3739ba3237 | 59 | segmentDisplay.LowerNumber(capSlider.get_position()); |
stevew817 | 0:9d3739ba3237 | 60 | } |
stevew817 | 0:9d3739ba3237 | 61 | |
stevew817 | 0:9d3739ba3237 | 62 | /*************************** MAIN *******************************/ |
stevew817 | 0:9d3739ba3237 | 63 | int main() { |
stevew817 | 0:9d3739ba3237 | 64 | // Initialize pushbutton handler |
stevew817 | 0:9d3739ba3237 | 65 | in.rise(NULL); |
stevew817 | 0:9d3739ba3237 | 66 | in.fall(in_handler); |
stevew817 | 0:9d3739ba3237 | 67 | |
stevew817 | 0:9d3739ba3237 | 68 | // Enable the capacitive slider |
stevew817 | 0:9d3739ba3237 | 69 | capSlider.start(); |
stevew817 | 0:9d3739ba3237 | 70 | capSlider.attach_touch(touchCallback); |
stevew817 | 0:9d3739ba3237 | 71 | capSlider.attach_untouch(touchCallback); |
stevew817 | 0:9d3739ba3237 | 72 | capSlider.attach_slide(-1, slideCallback); |
stevew817 | 0:9d3739ba3237 | 73 | |
stevew817 | 0:9d3739ba3237 | 74 | // Start generating the 1Hz timebase |
stevew817 | 0:9d3739ba3237 | 75 | refreshTicker.attach(&tickerCallback, 1.0f); |
stevew817 | 0:9d3739ba3237 | 76 | |
stevew817 | 0:9d3739ba3237 | 77 | printf("Initialization done! \n"); |
stevew817 | 6:c392ed815942 | 78 | wait(0.01f); //Need to delay slightly to give the serial transmission a chance to flush out its buffer |
stevew817 | 0:9d3739ba3237 | 79 | segmentDisplay.Write("Hello"); |
stevew817 | 0:9d3739ba3237 | 80 | |
stevew817 | 0:9d3739ba3237 | 81 | // Go into sleeping mode |
stevew817 | 0:9d3739ba3237 | 82 | while(1) |
stevew817 | 0:9d3739ba3237 | 83 | { |
stevew817 | 0:9d3739ba3237 | 84 | sleep(); |
stevew817 | 0:9d3739ba3237 | 85 | if(count >= 8) { |
stevew817 | 0:9d3739ba3237 | 86 | refreshTicker.detach(); |
stevew817 | 0:9d3739ba3237 | 87 | capSlider.stop(); |
stevew817 | 0:9d3739ba3237 | 88 | in.disable_irq(); |
stevew817 | 0:9d3739ba3237 | 89 | delete &segmentDisplay; |
stevew817 | 0:9d3739ba3237 | 90 | } |
stevew817 | 0:9d3739ba3237 | 91 | } |
stevew817 | 0:9d3739ba3237 | 92 | } |
stevew817 | 0:9d3739ba3237 | 93 |