Code for the nRF51822. The BLE advertises, connects to a master, sends information about the status of the LDRs and receives inputs from the Master
Dependencies: BLE_API mbed nRF51822
Fork of BLE_UART1 by
Diff: main.cpp
- Revision:
- 12:51e2c29e3019
- Parent:
- 11:4f9451eaca3d
- Child:
- 13:4e4ec6fe8123
--- a/main.cpp Sun Nov 09 21:06:47 2014 +0000 +++ b/main.cpp Sun Nov 09 23:51:54 2014 +0000 @@ -16,7 +16,6 @@ #include "mbed.h" #include "BLEDevice.h" -#include "Servo.h" #include <string.h> #include "UARTService.h" @@ -30,13 +29,29 @@ #define DEBUG(...) /* nothing */ #endif /* #if NEED_CONSOLE_OUTPUT */ +#define ON 1960 +#define OFF 40 +#define PULSE_WIDTH 2000 + BLEDevice ble; DigitalOut led1(LED1); DigitalOut led2(LED2); DigitalOut pwm_out(P0_30); +AnalogIn ldr0(P0_1); +AnalogIn ldr1(P0_2); +AnalogIn ldr2(P0_3); +AnalogIn ldr3(P0_4); + UARTService *uartServicePtr; +#define TIMER 1 +//Creating timer Instance + +Ticker ticker; +#if TIMER +long int timerCount = 0; +#endif void disconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason) { @@ -75,15 +90,30 @@ void periodicCallback(void) { +#if TIMER + timerCount++; + if ((timerCount < threshold)) + { + led1 = 1; + pwm_out = 1; + } + else + { + led1 = 0; + pwm_out = 0; + } + if (timerCount == PULSE_WIDTH) + timerCount = 0; +#else led1 = !led1; +#endif + } int main(void) { led1 = 1; - Ticker ticker; - ticker.attach(periodicCallback, 1); - + ticker.attach(periodicCallback, 0.000001f); DEBUG("Initialising the nRF51822\n\r"); ble.init(); ble.onDisconnection(disconnectionCallback); @@ -103,7 +133,7 @@ UARTService uartService(ble); uartServicePtr = &uartService; - while (true) { + while (true) { ble.waitForEvent(); } }