7-segment display with shift register. Common anode/cathode, any (eh, sort of) number of digits. Kind of framebuffer. Display has to be connected thru shift register, e.g. 4094. More details and picture in header file.

Committer:
amateusz
Date:
Sat Dec 19 13:30:30 2015 +0000
Revision:
0:55c62e840faf
Use a 7-segment display with any (eh, sort of) number of digits. Display connected with shift registers, e.g. 4094. More details and picture in header file.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
amateusz 0:55c62e840faf 1 /* This library lets to use a led display made of at most 8 segments as a screen buffer device. Like this one: https://www.dropbox.com/s/a3rvqahxhvpj0w3/general.jpg?dl=0
amateusz 0:55c62e840faf 2 The dispaly has to be made of two shift registers - i used 4094 and they are guaranteed to work, but others may also without any change to the code. The 8 digits limit can be easily overcomed daisy-chaining more shift registers. Have in mind though that it will cause the dispaly to be dimmer.
amateusz 0:55c62e840faf 3 This library lets you treat the display as a screen buffer device i.e. each digit is a byte-sized and bits are ordered as usual ABCDEFG scheme goes. Object has a field fb, which is the size you have it initialized.
amateusz 0:55c62e840faf 4 Size 4 by default. So just write to object.fb[n] whatever you want. You can do all sorts of bitwise operations. And then you have to take care of calling the draw() method periodcaly to update the display. (preffered way: use systick or timer).
amateusz 0:55c62e840faf 5 There is also provided function to convert most ASCII characters to bitmasked segments: digitORascii2char. It also allows to toggle a dot. Hope you like it.
amateusz 0:55c62e840faf 6 There is a bonus feature: you can arrange the common cathodes/anodes in any way in the shift registers, because you can initialise the library with given order of them.
amateusz 0:55c62e840faf 7 The same with segments. (in progress). Moreover there can be different layout of segments between each digit (also not done). Whoa!
amateusz 0:55c62e840faf 8 */
amateusz 0:55c62e840faf 9 #include "mbed.h"
amateusz 0:55c62e840faf 10
amateusz 0:55c62e840faf 11 #ifndef LED7segmDual4094_h
amateusz 0:55c62e840faf 12 #define LED7segmDual4094_h
amateusz 0:55c62e840faf 13
amateusz 0:55c62e840faf 14 class LED7segmDual4094{
amateusz 0:55c62e840faf 15 private:
amateusz 0:55c62e840faf 16 char _numOfSegments;
amateusz 0:55c62e840faf 17 unsigned int *_anodesBitMask;
amateusz 0:55c62e840faf 18 unsigned int _segmentsBitMask;
amateusz 0:55c62e840faf 19 bool _anodesActiveState;
amateusz 0:55c62e840faf 20 DigitalOut _data;
amateusz 0:55c62e840faf 21 DigitalOut _clock;
amateusz 0:55c62e840faf 22 DigitalOut _strobe;
amateusz 0:55c62e840faf 23 void send4094(unsigned short _load);
amateusz 0:55c62e840faf 24 public:
amateusz 0:55c62e840faf 25 LED7segmDual4094(PinName data, PinName clock, PinName strobe, char numOfSegments = 4);
amateusz 0:55c62e840faf 26 char *fb;
amateusz 0:55c62e840faf 27 void draw();
amateusz 0:55c62e840faf 28 void setAnodesBitMask(unsigned int *tab);
amateusz 0:55c62e840faf 29 void setAnodesActiveState(bool state);
amateusz 0:55c62e840faf 30 // void draw(char *tab);
amateusz 0:55c62e840faf 31 unsigned short load;
amateusz 0:55c62e840faf 32 //char i;
amateusz 0:55c62e840faf 33 char whichSegmMux;
amateusz 0:55c62e840faf 34 signed char digitORascii2char(char input, bool dot=0);
amateusz 0:55c62e840faf 35 // signed char return7seg;
amateusz 0:55c62e840faf 36
amateusz 0:55c62e840faf 37 };
amateusz 0:55c62e840faf 38
amateusz 0:55c62e840faf 39 #endif