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: SevenSegmentDisplay.cpp
- Revision:
- 0:9378fe6db796
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/SevenSegmentDisplay.cpp Thu Dec 11 08:01:43 2014 +0000
@@ -0,0 +1,70 @@
+#include "SevenSegmentDisplay.h"
+
+SevenSegmentDisplay::SevenSegmentDisplay(PinName a,
+ PinName b,
+ PinName c,
+ PinName d,
+ PinName e,
+ PinName f,
+ PinName g,
+ PinName dp,
+ ConnectionMode mode):
+ display(dp, g, f, e, d, c, b, a)
+{
+ display.output();
+ if (mode == CommonAnode)
+ display.mode(OpenDrain);
+ this->mode = mode;
+ init();
+}
+
+void SevenSegmentDisplay::init() {
+ if (mode == CommonAnode)
+ display = 0xFF;
+ else
+ display = 0x00;
+}
+
+void SevenSegmentDisplay::turnOn(int disp) {
+ if (mode == CommonAnode)
+ display = disp;
+ else
+ display = ~disp;
+}
+
+void SevenSegmentDisplay::print(char c) {
+ switch(c) { // a b c d e f g dp
+ case '0':
+ turnOn(0x03); // 0 0 0 0 0 0 1 1 (CommonAnode, ~CommonCathode)
+ break;
+ case '1':
+ turnOn(0x9F); // 1 0 0 1 1 1 1 1 (CommonAnode, ~CommonCathode)
+ break;
+ case '2':
+ turnOn(0x25); // 0 0 1 0 0 1 0 1 (CommonAnode, ~CommonCathode)
+ break;
+ case '3':
+ turnOn(0x0D); // 0 0 0 0 1 1 0 1 (CommonAnode, ~CommonCathode)
+ break;
+ case '4':
+ turnOn(0x99); // 1 0 0 1 1 0 0 1 (CommonAnode, ~CommonCathode)
+ break;
+ case '5':
+ turnOn(0x49); // 0 1 0 0 1 0 0 1 (CommonAnode, ~CommonCathode)
+ break;
+ case '6':
+ turnOn(0x41); // 0 1 0 0 0 0 0 1 (CommonAnode, ~CommonCathode)
+ break;
+ case '7':
+ turnOn(0x1F); // 0 0 0 1 1 1 1 1 (CommonAnode, ~CommonCathode)
+ break;
+ case '8':
+ turnOn(0x01); // 0 0 0 0 0 0 0 1 (CommonAnode, ~CommonCathode)
+ break;
+ case '9':
+ turnOn(0x09); // 0 0 0 0 1 0 0 1 (CommonAnode, ~CommonCathode)
+ break;
+ default:
+ init();
+ }
+}
\ No newline at end of file