void TIM3_IRQHandler(void) { static uint32_t tim3_cnt = 0; static uint32_t update_cnt = 0; static uint8_t button_cnt = 0; tim3_cnt++; update_cnt++; button_cnt++; OLED_Data[1][9] = systick_cnt/36000000%10 + '0'; OLED_Data[1][10] = systick_cnt/3600000%10 + '0'; OLED_Data[1][12] = systick_cnt/600000%6 + '0'; OLED_Data[1][13] = systick_cnt/60000%10 + '0'; OLED_Data[1][15] = systick_cnt/10000%6 + '0'; OLED_Data[1][16] = systick_cnt/1000%10 + '0'; OLED_Data[1][18] = systick_cnt/100%10 + '0'; OLED_Data[1][19] = systick_cnt/10%10 + '0'; if(update_cnt == 10) { update_cnt = 0; update_flag = 1; } button_detect(button_state); TIM_ClearFlag(TIM3,TIM_FLAG_Update); }
int main(void) { blue = LED_ON; green = LED_OFF; #if BUTTON_DOWN button.mode(PullDown); button.rise(button_wakeup); #else button.mode(PullUp); button.fall(button_wakeup); #endif DEBUG("Initialising the nRF51822\n\r"); ble.init(); ble.onConnection(connectionCallback); ble.onDisconnection(disconnectionCallback); ble.onDataWritten(onDataWritten); /* setup advertising */ ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE); ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); ble.accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME, (const uint8_t *)BLE_NAME, sizeof(BLE_NAME)); ble.setAdvertisingInterval(160); /* 100ms; in multiples of 0.625ms. */ ble.startAdvertising(); /* Enable over-the-air firmware updates. Instantiating DFUSservice introduces a * control characteristic which can be used to trigger the application to * handover control to a resident bootloader. */ DFUService dfu(ble); UARTService uartService(ble); uartServicePtr = &uartService; blue_led_time_to_off = 3000 / TICK_PERIOD_MS; Ticker ticker; ticker.attach_us(tick, TICK_PERIOD_MS * 1000); while (true) { if (button_event) { int click; blue = LED_ON; click = button_detect(); blue = LED_OFF; DEBUG("click type: %d\n\r", click); button_event = false; if (1 == click) { single_click_input = current_input; } else if (2 == click) { double_click_input = current_input; green = LED_ON; green_led_time_to_off = 1000 / TICK_PERIOD_MS; } else if (-1 == click) { while (BUTTON_DOWN == button.read()) { } nrf_delay_us(3000); power_down(); } else { continue; } DEBUG("typical input: %f, %f\n\r", single_click_input, double_click_input); threshold_update = 1; } else { ble.waitForEvent(); } } }