Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp@3:84cd01f2ee7d, 2020-10-26 (annotated)
- Committer:
- joes
- Date:
- Mon Oct 26 21:26:10 2020 +0000
- Revision:
- 3:84cd01f2ee7d
- Parent:
- 2:7235899a3ac7
CV04-Uloha1-minuta
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| _lukas_formanek | 2:7235899a3ac7 | 1 | #include "mbed.h" |
| _lukas_formanek | 2:7235899a3ac7 | 2 | #include "MyLed.h" |
| _lukas_formanek | 2:7235899a3ac7 | 3 | |
| joes | 3:84cd01f2ee7d | 4 | #define TICKER_TIME 60.0 // ticker period (1 second) |
| _lukas_formanek | 2:7235899a3ac7 | 5 | |
| _lukas_formanek | 2:7235899a3ac7 | 6 | MyLed led(LED1); // TO DO: implement methotds and use this class |
| _lukas_formanek | 2:7235899a3ac7 | 7 | |
| _lukas_formanek | 2:7235899a3ac7 | 8 | //DigitalOut led(LED1); // check pin on your board |
| _lukas_formanek | 2:7235899a3ac7 | 9 | InterruptIn sw(PA_0); // check pin on your board |
| _lukas_formanek | 2:7235899a3ac7 | 10 | |
| _lukas_formanek | 2:7235899a3ac7 | 11 | Serial pc(USBTX, USBRX,9600); // Tx pin, Rx pin, BaudRate |
| _lukas_formanek | 2:7235899a3ac7 | 12 | Ticker ticker; // ticker |
| _lukas_formanek | 0:99c19dff3a25 | 13 | |
| _lukas_formanek | 2:7235899a3ac7 | 14 | /* Global variables */ |
| _lukas_formanek | 2:7235899a3ac7 | 15 | volatile bool btnPressed = false; |
| _lukas_formanek | 2:7235899a3ac7 | 16 | volatile bool tick = false; |
| _lukas_formanek | 2:7235899a3ac7 | 17 | volatile uint8_t counter = 0; |
| _lukas_formanek | 0:99c19dff3a25 | 18 | |
| _lukas_formanek | 2:7235899a3ac7 | 19 | /* Button interrupt handler */ |
| _lukas_formanek | 2:7235899a3ac7 | 20 | void RiseHandler(void) |
| _lukas_formanek | 2:7235899a3ac7 | 21 | { |
| _lukas_formanek | 2:7235899a3ac7 | 22 | // led = !led; |
| _lukas_formanek | 2:7235899a3ac7 | 23 | btnPressed = true; |
| _lukas_formanek | 2:7235899a3ac7 | 24 | } |
| _lukas_formanek | 0:99c19dff3a25 | 25 | |
| _lukas_formanek | 2:7235899a3ac7 | 26 | /* Ticker interrupt handler */ |
| _lukas_formanek | 2:7235899a3ac7 | 27 | void OnTick(void) |
| _lukas_formanek | 2:7235899a3ac7 | 28 | { |
| _lukas_formanek | 2:7235899a3ac7 | 29 | tick = true; |
| _lukas_formanek | 2:7235899a3ac7 | 30 | counter++; |
| _lukas_formanek | 2:7235899a3ac7 | 31 | if(counter>60) { |
| _lukas_formanek | 2:7235899a3ac7 | 32 | counter = 0; |
| _lukas_formanek | 2:7235899a3ac7 | 33 | } |
| _lukas_formanek | 2:7235899a3ac7 | 34 | } |
| _lukas_formanek | 0:99c19dff3a25 | 35 | |
| _lukas_formanek | 0:99c19dff3a25 | 36 | int main() |
| _lukas_formanek | 0:99c19dff3a25 | 37 | { |
| _lukas_formanek | 2:7235899a3ac7 | 38 | pc.printf("\r\n----- Start of application ----- \r\n"); |
| joes | 3:84cd01f2ee7d | 39 | |
| joes | 3:84cd01f2ee7d | 40 | // led = 0; |
| _lukas_formanek | 2:7235899a3ac7 | 41 | ticker.attach(&OnTick,TICKER_TIME); |
| joes | 3:84cd01f2ee7d | 42 | |
| _lukas_formanek | 2:7235899a3ac7 | 43 | sw.rise(&RiseHandler); |
| _lukas_formanek | 2:7235899a3ac7 | 44 | |
| _lukas_formanek | 2:7235899a3ac7 | 45 | char z; |
| _lukas_formanek | 2:7235899a3ac7 | 46 | uint8_t period; |
| _lukas_formanek | 0:99c19dff3a25 | 47 | while (true) { |
| _lukas_formanek | 2:7235899a3ac7 | 48 | if(btnPressed) { |
| _lukas_formanek | 2:7235899a3ac7 | 49 | pc.printf("Button was pressed. \r\n"); |
| _lukas_formanek | 2:7235899a3ac7 | 50 | btnPressed = false; |
| _lukas_formanek | 2:7235899a3ac7 | 51 | } |
| joes | 3:84cd01f2ee7d | 52 | |
| joes | 3:84cd01f2ee7d | 53 | if(tick) { |
| joes | 3:84cd01f2ee7d | 54 | pc. printf("Counter value : %d \r\n", counter); |
| joes | 3:84cd01f2ee7d | 55 | tick = false; |
| joes | 3:84cd01f2ee7d | 56 | } |
| _lukas_formanek | 2:7235899a3ac7 | 57 | /* |
| _lukas_formanek | 2:7235899a3ac7 | 58 | if(pc.readable()) { |
| _lukas_formanek | 2:7235899a3ac7 | 59 | z = pc.getc(); |
| _lukas_formanek | 2:7235899a3ac7 | 60 | pc.printf("Pressed key : %c \r\n", z); |
| _lukas_formanek | 2:7235899a3ac7 | 61 | period = z - '0'; |
| _lukas_formanek | 2:7235899a3ac7 | 62 | if ((period >=0 )&&(period<=9)) { |
| _lukas_formanek | 2:7235899a3ac7 | 63 | pc.printf("\r\nperiod: %d \r\n",period); |
| _lukas_formanek | 2:7235899a3ac7 | 64 | led.SetBlinkPeriod(period); |
| _lukas_formanek | 2:7235899a3ac7 | 65 | } else |
| _lukas_formanek | 2:7235899a3ac7 | 66 | pc.printf("you entered the wrong value. \r\n"); |
| joes | 3:84cd01f2ee7d | 67 | }*/ |
| _lukas_formanek | 0:99c19dff3a25 | 68 | } |
| _lukas_formanek | 2:7235899a3ac7 | 69 | } |