flexSensor + ledPWM + bluetooth

Dependencies:   Map

Committer:
airaen0129
Date:
Sat Jul 20 02:11:20 2019 +0000
Revision:
1:0e180bcfcdae
Parent:
0:5f93dfb618bf
ledPWM + bt + flexSensor

Who changed what in which revision?

UserRevisionLine numberNew contents of line
airaen0129 0:5f93dfb618bf 1 /* mbed Microcontroller Library
airaen0129 0:5f93dfb618bf 2 * Copyright (c) 2018 ARM Limited
airaen0129 0:5f93dfb618bf 3 * SPDX-License-Identifier: Apache-2.0
airaen0129 0:5f93dfb618bf 4 */
airaen0129 0:5f93dfb618bf 5
airaen0129 0:5f93dfb618bf 6 #include "mbed.h"
airaen0129 0:5f93dfb618bf 7 #include "Map.hpp"
airaen0129 0:5f93dfb618bf 8
airaen0129 1:0e180bcfcdae 9 Serial pc(USBTX, USBRX);
airaen0129 1:0e180bcfcdae 10 Serial bt(PA_9, PA_10);
airaen0129 1:0e180bcfcdae 11 PwmOut ledPWM(PA_1);
airaen0129 0:5f93dfb618bf 12 AnalogIn flexSensor(PA_7);
airaen0129 1:0e180bcfcdae 13 Map map(0.8, 1.0, 0, 4);
airaen0129 1:0e180bcfcdae 14
airaen0129 0:5f93dfb618bf 15 int main() {
airaen0129 1:0e180bcfcdae 16 int analogValueLevel;
airaen0129 1:0e180bcfcdae 17
airaen0129 1:0e180bcfcdae 18 pc.baud(115200);
airaen0129 1:0e180bcfcdae 19 bt.baud(115200);
airaen0129 1:0e180bcfcdae 20 ledPWM.period(0.01f);
airaen0129 1:0e180bcfcdae 21 ledPWM = 0.0f;
airaen0129 1:0e180bcfcdae 22
airaen0129 1:0e180bcfcdae 23 pc.printf("Hello World! HC-06 bluetooth example...\n\r");
airaen0129 1:0e180bcfcdae 24
airaen0129 1:0e180bcfcdae 25 while (true) {
airaen0129 1:0e180bcfcdae 26 analogValueLevel = (int)map.Calculate(flexSensor);
airaen0129 0:5f93dfb618bf 27
airaen0129 1:0e180bcfcdae 28 bt.printf("%d\n", analogValueLevel);
airaen0129 1:0e180bcfcdae 29
airaen0129 1:0e180bcfcdae 30 ledPWM = 0.25f * analogValueLevel;
airaen0129 1:0e180bcfcdae 31
airaen0129 1:0e180bcfcdae 32 wait(0.5f);
airaen0129 0:5f93dfb618bf 33 }
airaen0129 0:5f93dfb618bf 34 }