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.
Fork of DACandticker_sample_with_debug by
Diff: main.cpp
- Revision:
- 4:75ad475aff41
- Parent:
- 3:2bf79a3c3cbc
- Child:
- 5:5161dd5f273e
--- a/main.cpp Wed Jan 23 17:56:42 2019 +0000
+++ b/main.cpp Mon Feb 04 16:12:23 2019 +0000
@@ -2,6 +2,10 @@
// -----------------------
// Periodically write to the AnalogOut to create a sine wave
// Alternate between two fixed frequencies every 5 sec
+//
+// This code uses the Ticker API to create a periodic interrupt
+// Devices used in this way must not call locks; a variant of
+// the AnalogOut device w/o locking is created for this.
//
// Updated for mbed 5
@@ -10,8 +14,21 @@
#include "mbed.h"
#include "sineTable.h"
+// --------------------------
+// This declaration introduces a derived version of the mbed AnalogOut
+// class with the locking removed.
+// You do NOT NEED TO UNDERSTAND this
+class AnalogOut_unsafe : public AnalogOut {
+ public:
+ AnalogOut_unsafe (PinName pin) : AnalogOut (pin) {}
+ protected:
+ virtual void lock() {}
+ virtual void unlock() {}
+};
+// --------------------------
+
Ticker tick ; // Creates periodic interrupt
-AnalogOut ao(PTE30) ; // Analog output
+AnalogOut_unsafe ao(PTE30) ; // Analog output
// Function called periodically
// Write new value to AnalogOut
