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.
Diff: main.cpp
- Revision:
- 2:7235899a3ac7
- Parent:
- 1:1579d36c7659
- Child:
- 3:84cd01f2ee7d
--- a/main.cpp Tue Oct 06 07:21:42 2020 +0000
+++ b/main.cpp Mon Oct 19 13:29:50 2020 +0000
@@ -1,23 +1,69 @@
-/* mbed Microcontroller Library
- * Copyright (c) 2019 ARM Limited
- * SPDX-License-Identifier: Apache-2.0
- */
+#include "mbed.h"
+#include "MyLed.h"
+
+#define TICKER_TIME 1.0 // ticker period (1 second)
+
+MyLed led(LED1); // TO DO: implement methotds and use this class
+
+//DigitalOut led(LED1); // check pin on your board
+InterruptIn sw(PA_0); // check pin on your board
+
+Serial pc(USBTX, USBRX,9600); // Tx pin, Rx pin, BaudRate
+Ticker ticker; // ticker
-#include "mbed.h"
-#include "platform/mbed_thread.h"
-
+/* Global variables */
+volatile bool btnPressed = false;
+volatile bool tick = false;
+volatile uint8_t counter = 0;
-// Blinking rate in milliseconds
-#define BLINKING_RATE_MS 500
+/* Button interrupt handler */
+void RiseHandler(void)
+{
+// led = !led;
+ btnPressed = true;
+}
+/* Ticker interrupt handler */
+void OnTick(void)
+{
+ tick = true;
+ counter++;
+ if(counter>60) {
+ counter = 0;
+ }
+}
int main()
{
- // Initialise the digital pin LED1 as an output
- DigitalOut led(LED1);
- // comment
+ pc.printf("\r\n----- Start of application ----- \r\n");
+ /*
+ led = 0;
+ ticker.attach(&OnTick,TICKER_TIME);
+ */
+ sw.rise(&RiseHandler);
+
+ char z;
+ uint8_t period;
while (true) {
- led = !led;
- thread_sleep_for(BLINKING_RATE_MS);
+ if(btnPressed) {
+ pc.printf("Button was pressed. \r\n");
+ btnPressed = false;
+ }
+ /*
+ if(tick) {
+ pc. printf("Counter value : %d \r\n", counter);
+ tick = false;
+ }
+ */
+ if(pc.readable()) {
+ z = pc.getc();
+ pc.printf("Pressed key : %c \r\n", z);
+ period = z - '0';
+ if ((period >=0 )&&(period<=9)) {
+ pc.printf("\r\nperiod: %d \r\n",period);
+ led.SetBlinkPeriod(period);
+ } else
+ pc.printf("you entered the wrong value. \r\n");
+ }
}
-}
+}
\ No newline at end of file