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.

Revision:
0:9d3739ba3237
Child:
4:4bd20d989554
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Apr 17 20:16:49 2015 +0000
@@ -0,0 +1,95 @@
+#include "test_env.h"
+
+#include "EFM32_SegmentLCD.h"
+#include "EFM32_CapSenseSlider.h"
+
+/******************** Define I/O *****************************/
+InterruptIn in(PB9);
+
+silabs::EFM32_SegmentLCD segmentDisplay;
+silabs::EFM32_CapSenseSlider capSlider;
+
+/******************** Define Timers *****************************/
+LowPowerTicker refreshTicker;
+
+/***************** Define global variables **********************/
+#define INIT_SECONDS		17600
+#define TEST_DURATION		10
+
+volatile uint32_t count = 0, seconds = INIT_SECONDS;
+
+
+/***************** Define callback handlers *********************/
+void tickerCallback(void);
+void in_handler();
+void touchCallback(void);
+void slideCallback(void);
+
+/**
+ * Callback for pushbutton interrupt
+ */
+void in_handler() {
+    count++;
+    segmentDisplay.ARing(count & 0x7, (count & 0x8) == 0);
+}
+
+/**
+ * Callback for 1 second timebase
+ */
+void tickerCallback(void) {
+	seconds++;
+	uint32_t clockValue = ((seconds / 60) % 60) * 100 + (seconds % 60);
+	segmentDisplay.Number(clockValue);
+	segmentDisplay.Symbol(LCD_SYMBOL_COL10, seconds & 0x1);
+}
+
+/**
+ * Callback for touching/untouching the cap slider
+ */
+void touchCallback(void) {
+    segmentDisplay.Symbol(LCD_SYMBOL_EFM32, capSlider.isTouched());
+
+    if(!capSlider.isTouched()) {
+        segmentDisplay.Write("Hello");
+    }
+}
+
+/**
+ * Callback for sliding the cap slider
+ */
+void slideCallback(void) {
+    segmentDisplay.LowerNumber(capSlider.get_position());
+}
+
+/*************************** MAIN *******************************/
+int main() {
+	// Initialize pushbutton handler
+	in.rise(NULL);
+	in.fall(in_handler);
+
+	// Enable the capacitive slider
+	capSlider.start();
+	capSlider.attach_touch(touchCallback);
+	capSlider.attach_untouch(touchCallback);
+	capSlider.attach_slide(-1, slideCallback);
+
+	// Start generating the 1Hz timebase
+	refreshTicker.attach(&tickerCallback, 1.0f);
+
+	printf("Initialization done! \n");
+
+	segmentDisplay.Write("Hello");
+
+	// Go into sleeping mode
+	while(1)
+	{
+		sleep();
+		if(count >= 8) {
+		    refreshTicker.detach();
+		    capSlider.stop();
+		    in.disable_irq();
+		    delete &segmentDisplay;
+		}
+	}
+}
+