Test program for magnetometer
Dependencies: mbed AES BLE_API nRF51822 smallAES
Diff: main.cpp
- Revision:
- 2:4871b5ad7938
- Parent:
- 1:b10a8955c2fc
- Child:
- 3:b9783107a8c4
--- a/main.cpp Thu May 03 10:47:54 2018 +0000 +++ b/main.cpp Mon Sep 30 10:38:33 2019 +0000 @@ -17,7 +17,8 @@ #include "mbed.h" #include "ble/BLE.h" #include "LEDService.h" -#include "ADCService.h" +#include "ButtonAService.h" +#include "accelService.h" /* * All the LEDs on the micro:bit are part of the LED Matrix, @@ -28,13 +29,15 @@ DigitalOut col1(P0_4, 0); DigitalOut alivenessLED(P0_13, 0); DigitalOut actuatedLED(P0_14, 0); -AnalogIn ADC(P0_3); -uint16_t ADCResult=0; -const static char DEVICE_NAME[] = "MrPotatoHead"; -static const uint16_t uuid16_list[] = {LEDService::LED_SERVICE_UUID,ADCService::ADC_SERVICE_UUID}; + +const static char DEVICE_NAME[] = "front1"; +//static const uint16_t uuid16_list[] = {LEDService::LED_SERVICE_UUID,ACCELService::ACCEL_SERVICE_UUID,ButtonAService::BUTTONA_SERVICE_UUID}; +static const uint16_t uuid16_list[] = {ACCELService::ACCEL_SERVICE_UUID}; LEDService *ledServicePtr; -ADCService *ADCServicePtr; +ButtonAService * btnAServicePtr; +ACCELService *AccelServicePtr; + Ticker ticker; void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params) @@ -44,7 +47,14 @@ void periodicCallback(void) { - alivenessLED = !alivenessLED; /* Do blinky on LED1 to indicate system aliveness. */ + + btnAServicePtr->poll(); + AccelServicePtr->poll(); + if (btnAServicePtr->GetButtonAState()) + alivenessLED = 1; + else + alivenessLED = 0; + } /** @@ -60,7 +70,8 @@ } void onDataReadCallback(const GattReadCallbackParams *params) { - ADCResult=ADC.read_u16(); + + } /** * This function is called when the ble initialization process has failed @@ -91,12 +102,13 @@ ble.gap().onDisconnection(disconnectionCallback); ble.gattServer().onDataWritten(onDataWrittenCallback); - ble.gattServer().onDataRead(onDataReadCallback); + // ble.gattServer().onDataRead(onDataReadCallback); // Nordic Soft device will not call this so have to poll instead bool initialValueForLEDCharacteristic = false; ledServicePtr = new LEDService(ble, initialValueForLEDCharacteristic); - ADCServicePtr = new ADCService(ble,ADCResult); - + btnAServicePtr = new ButtonAService(ble); + int16_t Tst=0; + AccelServicePtr = new ACCELService(ble,Tst); /* setup advertising */ ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE); ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, (uint8_t *)uuid16_list, sizeof(uuid16_list)); @@ -108,7 +120,7 @@ int main(void) { - ticker.attach(periodicCallback, 1); /* Blink LED every second */ + ticker.attach(periodicCallback, 1); /* Poll devices every 100ms */ BLE &ble = BLE::Instance(); ble.init(bleInitComplete); @@ -116,11 +128,7 @@ /* SpinWait for initialization to complete. This is necessary because the * BLE object is used in the main loop below. */ while (ble.hasInitialized() == false) { /* spin loop */ } - while (true) { ble.waitForEvent(); - ADCResult=ADC.read_u16(); - ADCServicePtr->updateADCValue(ADCResult); - } }