This program demonstrate how to apply BLE_nRF8001 library on mbed platform working with RedBearLab BLE Shield v2.1 or above.

Dependencies:   BLE_nRF8001 mbed

SimpleControls works with the BLEController iOS/Android App. The mbed's pin can acts as DIGITAL_IN, DIGITAL_OUT, PWM, SERVO, ANALOG_IN. The sketch is to show you how to control the pin as one of the abilities. Note that not every pin can own all of the abilities. You can change the following macro to specify which pin to be controlled.

DigitalInOut DIGITAL_OUT_PIN( PTD4 );

DigitalInOut DIGITAL_IN_PIN( PTA12 );

PwmOut pwm( PTA4 );

Servo myservo( PTA13 );

AnalogIn analog( PTB0 );

The application will report the state of DIGITAL_IN_PIN and ANALOG_IN_PIN to App. The App can control the state of DIGITAL_OUT_PIN / PWM_PIN / SERVO_PIN.

You have to change the belowing constructs manually corresponding to the platform you are using.

SPI spi(PTD2, PTD3, PTD1);

DigitalInOut BLE_RDY(PTA12);

DigitalInOut BLE_REQ(PTA2);

Committer:
RedBearLab
Date:
Wed Oct 22 05:01:13 2014 +0000
Revision:
0:4c34e71b2f6a
Child:
1:d743c358f812
First commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
RedBearLab 0:4c34e71b2f6a 1 #include "Servo.h"
RedBearLab 0:4c34e71b2f6a 2
RedBearLab 0:4c34e71b2f6a 3 Servo::Servo(PinName pin) : _servo(pin)
RedBearLab 0:4c34e71b2f6a 4 {
RedBearLab 0:4c34e71b2f6a 5 _servo.period_ms(20);
RedBearLab 0:4c34e71b2f6a 6 }
RedBearLab 0:4c34e71b2f6a 7
RedBearLab 0:4c34e71b2f6a 8 Servo::~Servo(void)
RedBearLab 0:4c34e71b2f6a 9 {
RedBearLab 0:4c34e71b2f6a 10
RedBearLab 0:4c34e71b2f6a 11 }
RedBearLab 0:4c34e71b2f6a 12
RedBearLab 0:4c34e71b2f6a 13 void Servo::write(unsigned char degree)
RedBearLab 0:4c34e71b2f6a 14 {
RedBearLab 0:4c34e71b2f6a 15 convert(degree);
RedBearLab 0:4c34e71b2f6a 16 _servo.pulsewidth_us(pulse);
RedBearLab 0:4c34e71b2f6a 17 }
RedBearLab 0:4c34e71b2f6a 18
RedBearLab 0:4c34e71b2f6a 19 void Servo::convert(unsigned char degree)
RedBearLab 0:4c34e71b2f6a 20 {
RedBearLab 0:4c34e71b2f6a 21 // 0~180 degree correspond to 500~2500
RedBearLab 0:4c34e71b2f6a 22 pulse = degree * 11 + 500;
RedBearLab 0:4c34e71b2f6a 23 }