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.
Dependencies: BMP280 ELEC350-Practicals-FZ429- TextLCD watchdog_RTOS BME280 ntp-client
Revision 0:f9a18207d99c, committed 2018-11-23
- Comitter:
- O_Thom
- Date:
- Fri Nov 23 14:42:48 2018 +0000
- Child:
- 1:f89c930c6491
- Commit message:
- Sampler class working
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.gitignore Fri Nov 23 14:42:48 2018 +0000 @@ -0,0 +1,4 @@ +.build +.mbed +projectfiles +*.py*
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/BME280.lib Fri Nov 23 14:42:48 2018 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/MACRUM/code/BME280/#c1f1647004c4
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/BMP280.lib Fri Nov 23 14:42:48 2018 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/charly/code/BMP280/#7a04d0f5950e
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ELEC350-Practicals-FZ429.lib Fri Nov 23 14:42:48 2018 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/teams/University-of-Plymouth-Stage-2-and-3/code/ELEC350-Practicals-FZ429/#8a08e08e4d25
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/README.md Fri Nov 23 14:42:48 2018 +0000 @@ -0,0 +1,57 @@ +# Getting started with Blinky on mbed OS + +This guide reviews the steps required to get Blinky working on an mbed OS platform. + +Please install [mbed CLI](https://github.com/ARMmbed/mbed-cli#installing-mbed-cli). + +## Import the example application + +From the command-line, import the example: + +``` +mbed import mbed-os-example-blinky +cd mbed-os-example-blinky +``` + +### Now compile + +Invoke `mbed compile`, and specify the name of your platform and your favorite toolchain (`GCC_ARM`, `ARM`, `IAR`). For example, for the ARM Compiler 5: + +``` +mbed compile -m K64F -t ARM +``` + +Your PC may take a few minutes to compile your code. At the end, you see the following result: + +``` +[snip] ++----------------------------+-------+-------+------+ +| Module | .text | .data | .bss | ++----------------------------+-------+-------+------+ +| Misc | 13939 | 24 | 1372 | +| core/hal | 16993 | 96 | 296 | +| core/rtos | 7384 | 92 | 4204 | +| features/FEATURE_IPV4 | 80 | 0 | 176 | +| frameworks/greentea-client | 1830 | 60 | 44 | +| frameworks/utest | 2392 | 512 | 292 | +| Subtotals | 42618 | 784 | 6384 | ++----------------------------+-------+-------+------+ +Allocated Heap: unknown +Allocated Stack: unknown +Total Static RAM memory (data + bss): 7168 bytes +Total RAM memory (data + bss + heap + stack): 7168 bytes +Total Flash memory (text + data + misc): 43402 bytes +Image: .\.build\K64F\ARM\mbed-os-example-blinky.bin +``` + +### Program your board + +1. Connect your mbed device to the computer over USB. +1. Copy the binary file to the mbed device. +1. Press the reset button to start the program. + +The LED on your platform turns on and off. + +## Troubleshooting + +If you have problems, you can review the [documentation](https://os.mbed.com/docs/latest/tutorials/debugging.html) for suggestions on what could be wrong and how to fix it.
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/SWPoll.hpp Fri Nov 23 14:42:48 2018 +0000
@@ -0,0 +1,70 @@
+#include "mbed.h"
+class SWPoll {
+private:
+ enum State {LOW, LOW_DEBOUNCE, HIGH, HIGH_DEBOUNCE};
+ State state; // Internal state
+ DigitalIn& sw; // These are references (aliases) and MUST be initialised
+ int status; // ""
+ Timer t; // Each instance has it's own timer, so this is is finite
+
+public:
+ //Constructor - MUST be given two parameters (for the switch and led) BY REFERENCE
+ SWPoll(DigitalIn& gpioIn, int flag) : sw(gpioIn), status(flag) {
+ state = LOW;
+ t.reset();
+ flag = 0;
+ }
+ //Destructor - should the instance go out of scope, this is called
+ ~SWPoll() {
+ //Shut down
+ t.stop();
+ t.reset();
+ flag = 0;
+ }
+ //The public API - poll the switches
+ //Bascially, a mealy machine - uses a timer to manage switch bounce
+ void poll() {
+ switch (state)
+ {
+ //Waiting for switch to rise:
+ case LOW:
+ if (sw == 1) {
+ state = LOW_DEBOUNCE;
+ t.reset();
+ t.start();
+ }
+ break;
+
+ case LOW_DEBOUNCE:
+ if (t.read_ms() >= 200) {
+ state = HIGH;
+ t.stop();
+ t.reset();
+ }
+ break;
+
+ case HIGH:
+ if (sw == 0) {
+ flag = !flag; //Toggle output on state transition
+ state = HIGH_DEBOUNCE;
+ t.reset(); //(purely defensive)
+ t.start();
+ }
+ break;
+ case HIGH_DEBOUNCE:
+ if (t.read_ms() >= 200) {
+ state = LOW;
+ t.stop();
+ t.reset();
+ }
+ break;
+ default:
+ t.stop();
+ t.reset();
+ state = LOW;
+ break;
+ } //end switch
+
+ //This is a Mealy Machine - so no output logic follows
+ }
+};
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Sampler.hpp Fri Nov 23 14:42:48 2018 +0000
@@ -0,0 +1,68 @@
+#include "mbed.h"
+#define Activate_Flag 1
+
+class Sampler
+{
+ friend class Ticker;
+
+private:
+ Ticker t; // Time Initialisation
+ Thread t1; // Sample Thread
+public:
+
+ void start()
+ {
+ // t.attach(Callback(this,&doISR), 2); // Start the ticker to 0.5 seconds to test
+ t.attach(Callback<void()>(this, &Sampler::doISR), 2);
+ post(); // Hardware Testing
+ }
+
+ void doISR()
+ {
+ t1.signal_set(Activate_Flag); // Signal the sampling thread to move from WAITING to READY
+ }
+
+
+
+ static void samplingThread()
+ {
+ int idx = 0;
+ while(1)
+ {
+ Thread::signal_wait(Activate_Flag);
+ idx++;
+ printf("\033[2J"); // Clear screen
+ printf("\033[H"); // Home Position
+ printf("**********Sample %d**********\n", idx);
+ printf("SW1: %d\tSW2: %d\n\r", SW1.read(), SW2.read());
+ printf("LDR: %f\n\r", adcIn.read()*4095);
+ float temp = sensor.getTemperature();
+ float pressure = sensor.getPressure();
+ #ifdef BME
+ float humidity = sensor.getHumidity();
+ #endif
+ printf("Temperature: %5.1f\n", temp);
+ printf("Pressure: %5.1f\n", pressure);
+ #ifdef BME
+ printf("Pressure: %5.1f\n", humidity);
+ #endif
+ puts("**********POST END**********");
+ }
+ }
+
+ Sampler()
+ { //Constructor
+ // IDs
+ osThreadId idMain;
+ osThreadId idSample;
+ idMain = osThreadGetId(); // CMSIS RTOS Call
+ idSample = t1.gettid(); // Assign the id to the thread handle (Check this)
+ t1.start(samplingThread); // Start the sampling thread
+ //NVIC_SetPriority(TIMER0_IRQn,osPriorityHigh); // Uncomment for priority setting in the NVIC
+ }
+ //Destructor - should the instance go out of scope, this is called
+ ~Sampler()
+ {
+ t.detach();
+ }
+};
\ No newline at end of file
Binary file img/uvision.png has changed
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Fri Nov 23 14:42:48 2018 +0000
@@ -0,0 +1,14 @@
+/* Sampling Code */
+ #include "mbed.h"
+#include "sample_hardware.hpp"
+#include "Sampler.hpp"
+
+EventQueue mainQueue;
+
+Sampler s; // Initialise the s object
+
+int main()
+{
+ s.start();
+ Thread::wait(osWaitForever);
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-os.lib Fri Nov 23 14:42:48 2018 +0000 @@ -0,0 +1,1 @@ +https://github.com/ARMmbed/mbed-os/#2fd0c5cfbd83fce62da6308f9d64c0ab64e1f0d6
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sd-driver.lib Fri Nov 23 14:42:48 2018 +0000 @@ -0,0 +1,1 @@ +https://github.com/ARMmbed/sd-driver/#ae7e7440054c9447f8255bdccbcc523b3f6dffe4