
Charles Young's development fork. Going forward I only want to push mature code to main repository.
Fork of GEO_COUNTER_L432KC by
Diff: main.cpp
- Revision:
- 7:9f975e00600c
- Parent:
- 6:05201ecabb95
- Child:
- 8:5e70ca85fcb1
- Child:
- 10:f48cc6be5ae8
--- a/main.cpp Sun Sep 02 17:25:48 2018 -0700 +++ b/main.cpp Sun Sep 02 17:47:14 2018 -0700 @@ -38,6 +38,9 @@ #define CNT2 0x20 #define HV 0x40 #define MENU 0x80 +uint8_t LED_statuses [CPM, CPS, PLS, VOLTS, CNT1, CNT2, HV, MENU]; +uint8_t LED_status = CPM; +uint8_t LED_status_index = 0; // definitions of the input/outputs (pins) DigitalOut AUX (D2); // AUX control for GPS module @@ -60,7 +63,14 @@ DigitalOut led1(LED1); // definitions of peripherals and devices + +// QEI class supports the mode wheel. In its most basic function it will tell +// us which direction the wheel is moving (right or left) so that we can +// use it to select the current mode. QEI Wheel(D12, D11, NC, 16); // Quadrature encoder +int WheelCurrent = 0; +int WheelPrevious = 0; + I2C i2c(D4, D5); // I2C port Ticker Sec_Beat; // 1 second ticker Serial PC(USBTX, USBRX); // Virtual COM via USB (PC connection) @@ -122,9 +132,6 @@ LEDs_write(0x00); // initialize LEDs (CPM and CNT1 on) Beep(); // initial beep - uint8_t LED_status = CNT1 | CPS; - LEDs_write(LED_status); - // set the 1 sec ticker to periodically call the Update() routine // NOTE: this is also the 1-sec time base for counters. A better approach // would replace the ticker with an interrupt from the RTC (to be implemented) @@ -150,6 +157,8 @@ void Update() { + LEDs_write(LED_statuses[LED_status_index]); + ADC_val = KEYB.read(); // read voltage from keyboard PC.printf("\nADC: %.02f", ADC_val); if ( (ADC_val<0.1) // START/STOP pushbutton pressed @@ -213,9 +222,15 @@ strftime(Text, 50, "%H:%M:%S", localtime(&seconds)); PC.printf(" RTC: %s, CNT1: %7d CNT2: %7d",Text, Count1, Count2); - value = int(Wheel.getPulses()); - PC.printf(" started %d", value); - + WheelCurrent = int(Wheel.getPulses()); + PC.printf(" started %d", WheelCurrent); + if (WheelCurrent > WheelPrevious) + LED_status_index++ | sizeof(LED_statuses); + else + if (WheelCurrent < WheelPrevious) + LED_status_index-- | sizeof(LED_statuses); + WheelPrevious = WheelCurrent; + return; }