This is a very simple guide, reviewing the steps required to get Blinky working on an Mbed OS platform.

Dependencies:   RemoteIR

Committer:
sb8718
Date:
Sat Apr 18 15:02:33 2020 +0000
Revision:
122:2c65a61b756d
Parent:
121:450f119863a7
Child:
123:c9734480ca03
Lab 3_4 (not Lab 2_4)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sb8718 109:5274dd9bebe1 1 #include "mbed.h"
sb8718 119:d879334e3d87 2 #include <string.h>
sb8718 117:cc2a98cdd8fa 3
sb8718 121:450f119863a7 4 RawSerial pc(PA_2, PA_3,115200);
sb8718 120:a1dd83d9c036 5
sb8718 122:2c65a61b756d 6 bool on = false;
sb8718 122:2c65a61b756d 7 InterruptIn button(USER_BUTTON);
sb8718 116:82faef102371 8
sb8718 122:2c65a61b756d 9 Timer timer;
sb8718 122:2c65a61b756d 10 Timer intervalTimer;
sb8718 122:2c65a61b756d 11 Timer intTimer;
sb8718 119:d879334e3d87 12
sb8718 122:2c65a61b756d 13 void fall_down() {
sb8718 121:450f119863a7 14
sb8718 122:2c65a61b756d 15 // pc.printf("fall down\r\n");
sb8718 121:450f119863a7 16
sb8718 122:2c65a61b756d 17 intTimer.reset();
sb8718 122:2c65a61b756d 18 intTimer.start();
sb8718 121:450f119863a7 19 }
sb8718 121:450f119863a7 20
sb8718 122:2c65a61b756d 21 void rise_up() {
sb8718 122:2c65a61b756d 22
sb8718 122:2c65a61b756d 23 float timeFromStart = timer.read();
sb8718 122:2c65a61b756d 24 float timeToInterval = intervalTimer.read();
sb8718 122:2c65a61b756d 25
sb8718 122:2c65a61b756d 26 // pc.printf("rise up\r\n");
sb8718 117:cc2a98cdd8fa 27
sb8718 122:2c65a61b756d 28 if(!on) {
sb8718 122:2c65a61b756d 29
sb8718 122:2c65a61b756d 30 pc.printf("Start\r\n");
sb8718 122:2c65a61b756d 31
sb8718 122:2c65a61b756d 32 timer.reset();
sb8718 122:2c65a61b756d 33 intervalTimer.reset();
sb8718 122:2c65a61b756d 34 timer.start();
sb8718 122:2c65a61b756d 35 intervalTimer.start();
sb8718 122:2c65a61b756d 36 on = true;
sb8718 122:2c65a61b756d 37 return;
sb8718 122:2c65a61b756d 38 }
sb8718 122:2c65a61b756d 39
sb8718 122:2c65a61b756d 40 float clikingTime = intTimer.read();
sb8718 118:88f30fadf08f 41
sb8718 122:2c65a61b756d 42 pc.printf("The time from start click: %.3f\r\n", timeFromStart);
sb8718 122:2c65a61b756d 43 pc.printf("The time from previous click: %.3f\r\n", timeToInterval);
sb8718 122:2c65a61b756d 44
sb8718 122:2c65a61b756d 45 if(clikingTime >= 1) {
sb8718 122:2c65a61b756d 46
sb8718 122:2c65a61b756d 47 pc.printf("Stop\r\n");
sb8718 122:2c65a61b756d 48 on = false;
sb8718 122:2c65a61b756d 49 return;
sb8718 117:cc2a98cdd8fa 50 }
sb8718 122:2c65a61b756d 51
sb8718 122:2c65a61b756d 52 intervalTimer.reset();
sb8718 117:cc2a98cdd8fa 53 }
sb8718 121:450f119863a7 54
sb8718 122:2c65a61b756d 55
sb8718 118:88f30fadf08f 56 int main() {
sb8718 119:d879334e3d87 57
sb8718 122:2c65a61b756d 58 pc.printf("Welcome to StopWatch!\r\n");
sb8718 117:cc2a98cdd8fa 59
sb8718 122:2c65a61b756d 60 button.rise(&rise_up);
sb8718 122:2c65a61b756d 61 button.fall(&fall_down);
sb8718 119:d879334e3d87 62
sb8718 119:d879334e3d87 63 while(true) {
sb8718 118:88f30fadf08f 64 }
sb8718 109:5274dd9bebe1 65 }