micro:bit мигалка

Dependencies:   mbed BLE_API nRF51822

Программа для исполнительного устройства на micro:bit (nRF51822), включение\выключение светодиода по команде с управляющего устройства на nRF51822.

Committer:
mamont090671
Date:
Sat Dec 14 07:43:55 2019 +0000
Revision:
3:69ccae6ab80a
Parent:
0:8ae63d3cc188
+1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Alexgerni 0:8ae63d3cc188 1 /* mbed Microcontroller Library
Alexgerni 0:8ae63d3cc188 2 * Copyright (c) 2006-2013 ARM Limited
Alexgerni 0:8ae63d3cc188 3 *
Alexgerni 0:8ae63d3cc188 4 * Licensed under the Apache License, Version 2.0 (the "License");
Alexgerni 0:8ae63d3cc188 5 * you may not use this file except in compliance with the License.
Alexgerni 0:8ae63d3cc188 6 * You may obtain a copy of the License at
Alexgerni 0:8ae63d3cc188 7 *
Alexgerni 0:8ae63d3cc188 8 * http://www.apache.org/licenses/LICENSE-2.0
Alexgerni 0:8ae63d3cc188 9 *
Alexgerni 0:8ae63d3cc188 10 * Unless required by applicable law or agreed to in writing, software
Alexgerni 0:8ae63d3cc188 11 * distributed under the License is distributed on an "AS IS" BASIS,
Alexgerni 0:8ae63d3cc188 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Alexgerni 0:8ae63d3cc188 13 * See the License for the specific language governing permissions and
Alexgerni 0:8ae63d3cc188 14 * limitations under the License.
Alexgerni 0:8ae63d3cc188 15 */
Alexgerni 0:8ae63d3cc188 16
Alexgerni 0:8ae63d3cc188 17 #ifndef __BLE_LED_SERVICE_H__
Alexgerni 0:8ae63d3cc188 18 #define __BLE_LED_SERVICE_H__
Alexgerni 0:8ae63d3cc188 19
Alexgerni 0:8ae63d3cc188 20 class LEDService {
Alexgerni 0:8ae63d3cc188 21 public:
Alexgerni 0:8ae63d3cc188 22 const static uint16_t LED_SERVICE_UUID = 0xA000;
Alexgerni 0:8ae63d3cc188 23 const static uint16_t LED_STATE_CHARACTERISTIC_UUID = 0xA001;
Alexgerni 0:8ae63d3cc188 24
Alexgerni 0:8ae63d3cc188 25 LEDService(BLEDevice &_ble, bool initialValueForLEDCharacteristic) :
Alexgerni 0:8ae63d3cc188 26 ble(_ble), ledState(LED_STATE_CHARACTERISTIC_UUID, &initialValueForLEDCharacteristic)
Alexgerni 0:8ae63d3cc188 27 {
Alexgerni 0:8ae63d3cc188 28 GattCharacteristic *charTable[] = {&ledState};
Alexgerni 0:8ae63d3cc188 29 GattService ledService(LED_SERVICE_UUID, charTable, sizeof(charTable) / sizeof(GattCharacteristic *));
Alexgerni 0:8ae63d3cc188 30 ble.addService(ledService);
Alexgerni 0:8ae63d3cc188 31 }
Alexgerni 0:8ae63d3cc188 32
Alexgerni 0:8ae63d3cc188 33 GattAttribute::Handle_t getValueHandle() const {
Alexgerni 0:8ae63d3cc188 34 return ledState.getValueHandle();
Alexgerni 0:8ae63d3cc188 35 }
Alexgerni 0:8ae63d3cc188 36
Alexgerni 0:8ae63d3cc188 37 private:
Alexgerni 0:8ae63d3cc188 38 BLEDevice &ble;
Alexgerni 0:8ae63d3cc188 39 ReadWriteGattCharacteristic<bool> ledState;
Alexgerni 0:8ae63d3cc188 40 };
Alexgerni 0:8ae63d3cc188 41
Alexgerni 0:8ae63d3cc188 42 #endif /* #ifndef __BLE_LED_SERVICE_H__ */