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.
Dependencies: BLE_API nRF51822 mbed
Fork of KS7 by
Diff: main.cpp
- Branch:
- KS3
- Revision:
- 24:c6ef55535900
- Parent:
- 23:ca1806081f0c
- Child:
- 25:da723b86c60b
--- a/main.cpp Tue Mar 22 09:22:51 2016 +0000
+++ b/main.cpp Mon Mar 28 02:15:04 2016 +0000
@@ -221,22 +221,12 @@
int main()
{
+ float weight_s;
+ int Navg = 5;
+ int sample = 0;
#ifdef UART_DEBUG
pc.baud(UART_BAUD_RATE);
#endif
-/*
- // debug for PCB_VER4
- io.analog_pow(1);
- // 0g = 0.509444 * 16777215 = 8547051
- // 2000g = 0.588761 * 16777215 = 9877770
- // d = 0.079317/2kg = 1330719/2kg = 665.36/g
- uint32_t d0 = io._get_adc_raw(0);
- while(1) {
- uint32_t d = io._get_adc_raw(0);
- if (d > d0) d = d - d0; else d = 0;
- pc.printf("%d %d %f\r\n", io.get_switch(), d, (float)d / 665.36);
- }
-*/
#ifdef PCB_VER3
// set XTAL=32MHz for TaiyoYuden's module
// is moved to mbed-src/targets/cmsis/TARGET_NORDIC/TARGET_MCU_NRF51822/system_nrf51.c
@@ -247,19 +237,13 @@
AppInit();
led_mode = MODE_OFF;
for (;; ) {
- pc.printf("#");
// 100msec waitForEvent
t.reset();
while(t.read_ms() < LED_INTERVAL_MSEC) {
- pc.printf(".");
t.start();
ble.waitForEvent();
t.stop();
}
-
- pc.printf("$");
- pc.printf("%d %d\r\n", led_mode, io.get_switch());
- // ticker蜃ヲ逅・
switch(led_mode) {
case MODE_OFF:
io.analog_pow(0);
@@ -270,8 +254,8 @@
break;
case MODE_START:
io.analog_pow(1);
+ io.power_save_mode(0);
led_brightness += BRIGHTNESS_ADDVALUE;
- pc.printf("br=%f/%f\r\n", led_brightness, BRIGHTNESS_MAXVALUE);
io.display(led_brightness);
if(led_brightness >= BRIGHTNESS_MAXVALUE) {
update_counter = 0;
@@ -281,9 +265,14 @@
#endif
ble.startAdvertising();
led_mode = MODE_ON;
+ weight_s = 0.0;
+ sample = 0;
}
break;
case MODE_ON:
+#ifdef UART_DEBUG
+// pc.printf("%d %d %.2f\r\n", io.get_switch(), io.get_weight_raw(), io.get_weight());
+#endif
io.analog_pow(1);
if(io.get_switch()) {
led_mode = MODE_END;
@@ -298,12 +287,15 @@
(uint8_t *)&scale,
sizeof(scale));
-// weight = io.get_weight_raw() / WEIGHT_COEFFICIENT;
-// if(weight < 0) {
-// weight = 0;
-// }
- weight = io.get_weight();
- io.display_value = (uint16_t)weight;
+ weight_s += io.get_weight();
+ sample++;
+ if (sample == Navg){
+ weight = weight_s / (float)Navg;
+ io.display_value = (uint16_t)weight;
+ weight_s = 0.0;
+ sample = 0;
+ }
+// pc.printf("weight=%.1f\r\n", weight);
// io.display_value = 8888; // for LED soldering check
#ifdef UART_DEBUG
// pc.printf("%d\r\n", io._get_adc_raw(0));
@@ -327,6 +319,7 @@
SWInit();
#endif
led_mode = MODE_OFF;
+ io.power_save_mode(1);
}
break;
}
