Primi test su EMF32

Dependencies:   EFM32_CapSenseSlider EFM32_SegmentLCD mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "EFM32_SegmentLCD.h"
00002 #include "EFM32_CapSenseSlider.h"
00003 
00004 /******************** Define I/O *****************************/
00005 InterruptIn in0(PB9);
00006 InterruptIn in1(PB10);
00007 
00008 silabs::EFM32_SegmentLCD segmentDisplay;
00009 silabs::EFM32_CapSenseSlider capSlider;
00010 
00011 /******************** Define Timers *****************************/
00012 LowPowerTicker refreshTicker;
00013 
00014 /***************** Define global variables **********************/
00015 #define INIT_SECONDS        17600
00016 #define TEST_DURATION       10
00017 
00018 volatile uint32_t seconds = INIT_SECONDS;
00019 int count = -1;
00020 
00021 
00022 /***************** Define callback handlers *********************/
00023 void tickerCallback(void);
00024 void in0_handler();
00025 void in1_handler();
00026 void touchCallback(void);
00027 void slideCallback(void);
00028 
00029 /**
00030  * Callback for pushbutton interrupt
00031  */
00032 
00033 void symbolGest()
00034 {
00035     if (count==7) {
00036         segmentDisplay.Symbol(LCD_SYMBOL_GECKO, true);
00037         segmentDisplay.Write("GeckoOn");
00038     } else {
00039         segmentDisplay.Symbol(LCD_SYMBOL_GECKO, false);
00040         if (count%2==0) segmentDisplay.Write("Scorda");
00041         else  segmentDisplay.Write("TataGek");
00042     }
00043 
00044 }
00045 
00046 void in0_handler()
00047 {
00048     count++;
00049     if (count>7) count=7;
00050     else segmentDisplay.ARing(count, true);
00051     symbolGest() ;
00052 
00053 }
00054 
00055 void in1_handler()
00056 {
00057     segmentDisplay.ARing(count, false);
00058     count--;
00059     if (count<0) count=-1;
00060     symbolGest() ;
00061 
00062 }
00063 
00064 
00065 /**
00066  * Callback for 1 second timebase
00067  */
00068 void tickerCallback(void)
00069 {
00070     seconds++;
00071     uint32_t clockValue = ((seconds / 60) % 60) * 100 + (seconds % 60);
00072     segmentDisplay.Number(clockValue);
00073     segmentDisplay.Symbol(LCD_SYMBOL_COL10, seconds & 0x1);
00074 }
00075 
00076 /**
00077  * Callback for touching/untouching the cap slider
00078  */
00079 void touchCallback(void)
00080 {
00081     segmentDisplay.Symbol(LCD_SYMBOL_EFM32, capSlider.isTouched());
00082 
00083     if(!capSlider.isTouched()) {
00084         segmentDisplay.Write("Scorda");
00085     }
00086 }
00087 
00088 /**
00089  * Callback for sliding the cap slider
00090  */
00091 void slideCallback(void)
00092 {
00093     segmentDisplay.LowerNumber(capSlider.get_position());
00094 }
00095 
00096 /*************************** MAIN *******************************/
00097 int main()
00098 {
00099     // Initialize pushbutton handler
00100     in0.rise(NULL);
00101     in0.fall(in0_handler);
00102 
00103     in1.rise(NULL);
00104     in1.fall(in1_handler);
00105 
00106     // Enable the capacitive slider
00107     capSlider.start();
00108     capSlider.attach_touch(touchCallback);
00109     capSlider.attach_untouch(touchCallback);
00110     capSlider.attach_slide(-1, slideCallback);
00111 
00112     // Start generating the 1Hz timebase
00113     refreshTicker.attach(&tickerCallback, 1.0f);
00114 
00115     printf("Initialization done! \n");
00116     wait(0.01f); //Need to delay slightly to give the serial transmission a chance to flush out its buffer
00117     segmentDisplay.Write("Scorda");
00118 
00119 
00120     // Go into sleeping mode
00121     while(1) {
00122         sleep();
00123 
00124         if(count >= 8) {
00125             /*
00126                     // Go to 'completely dead' mode to show power consumption
00127                     refreshTicker.detach();
00128                     capSlider.stop();
00129                     in.disable_irq();
00130                     delete &segmentDisplay;
00131 
00132                     */
00133         }
00134 
00135     }
00136 }
00137