for BLE Nano v1 INPUT : Analog OUTPUT : USB Serial
Dependencies: BLE_API mbed nRF51822
Revision 0:42bf46ed69f7, committed 2018-07-12
- Comitter:
- electricbaka
- Date:
- Thu Jul 12 15:48:28 2018 +0000
- Commit message:
- init
Changed in this revision
diff -r 000000000000 -r 42bf46ed69f7 BLE_API.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/BLE_API.lib Thu Jul 12 15:48:28 2018 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/teams/Bluetooth-Low-Energy/code/BLE_API/#65474dc93927
diff -r 000000000000 -r 42bf46ed69f7 Servo.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Servo.cpp Thu Jul 12 15:48:28 2018 +0000 @@ -0,0 +1,42 @@ +/* + +Copyright (c) 2012-2014 RedBearLab + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software +and associated documentation files (the "Software"), to deal in the Software without restriction, +including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, +and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE +FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +*/ + +#include "Servo.h" + +Servo::Servo(PinName pin) : _servo(pin) +{ + _servo.period_ms(20); +} + +Servo::~Servo(void) +{ + +} + +void Servo::write(unsigned char degree) +{ + convert(degree); + _servo.pulsewidth_us(pulse); +} + +void Servo::convert(unsigned char degree) +{ + // 0~180 degree correspond to 500~2500 + pulse = degree * 11 + 500; +}
diff -r 000000000000 -r 42bf46ed69f7 Servo.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Servo.h Thu Jul 12 15:48:28 2018 +0000 @@ -0,0 +1,40 @@ +/* + +Copyright (c) 2012-2014 RedBearLab + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software +and associated documentation files (the "Software"), to deal in the Software without restriction, +including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, +and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE +FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +*/ + +#ifndef _SERVO_H +#define _SERVO_H + +#include "mbed.h" + +class Servo +{ +public: + Servo(PinName pin); + ~Servo(void); + + void write(unsigned char degree); + +private: + void convert(unsigned char degree); + + PwmOut _servo; + unsigned int pulse; +}; + +#endif \ No newline at end of file
diff -r 000000000000 -r 42bf46ed69f7 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Jul 12 15:48:28 2018 +0000 @@ -0,0 +1,42 @@ +/* + * + * BLE Nano1 : USB Serial Communication + * + * http://jellyware.jp/kurage/ + * + */ + + +//------------------------------------------------------------ +//Include Header Files +//------------------------------------------------------------ +#include "mbed.h" + + +//------------------------------------------------------------ +//Definition +//------------------------------------------------------------ +#define ANALOG_IN_PIN1 P0_4 + + +//------------------------------------------------------------ +//Object generation +//------------------------------------------------------------ +AnalogIn ANALOG1(ANALOG_IN_PIN1); +Serial pc(P0_9, P0_11); + +int main(void) +{ + pc.baud(9600); + char str[10]; + + while (true) { + float s = ANALOG1; + uint16_t value = s * 1024; + + sprintf(str, "%d\r\n", value); + pc.printf(str); + + wait_ms(1); + } +} \ No newline at end of file
diff -r 000000000000 -r 42bf46ed69f7 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Thu Jul 12 15:48:28 2018 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/mbed_official/code/mbed/builds/a7c7b631e539 \ No newline at end of file
diff -r 000000000000 -r 42bf46ed69f7 nRF51822.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nRF51822.lib Thu Jul 12 15:48:28 2018 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/teams/Nordic-Semiconductor/code/nRF51822/#c90ae1400bf2