6 x 7 segment display library for PCA9637 driven breakout board
Dependents: FTSE100 InternetDispBoB digitalThermometer Counter ... more
Revision 0:843654413849, committed 2011-06-29
- Comitter:
- d_worrall
- Date:
- Wed Jun 29 11:23:47 2011 +0000
- Child:
- 1:d3d2fb119fa3
- Commit message:
- version1
Changed in this revision
dispBoB.cpp | Show annotated file Show diff for this revision Revisions of this file |
dispBoB.h | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dispBoB.cpp Wed Jun 29 11:23:47 2011 +0000 @@ -0,0 +1,100 @@ +//NXP PCA9635 library +//mbed Team - 28th June 2011 +//Daniel Worrall + +#include "mbed.h" +#include "PCA9635.h" +#include "dispBoB.h" + +Serial pc(USBTX, USBRX); + + static const char _loc[] = {0x02, 0x02, 0x04, 0x04, 0x10, 0x10, 0x12, 0x12}; + static const short _disp[] = { + 0xE00E, 0x2008, 0xC00D, 0x600D, 0x200B, 0x6007, 0xE007, 0x200E, 0xE00F, 0x600F, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0xF001, 0xE003, 0xC001, 0xE009, 0xC007, 0x8007, 0x600F, 0xA003, 0x8000, 0x6008, 0xA007, 0x3008, 0xA005, 0xA001, 0xE001, + 0x800F, 0x300F, 0x8001, 0x6007, 0xC003, 0xE000, 0xE000, 0xE004, 0xA00B, 0x600B, 0xC00D, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x1000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + + 0x0EE0, 0x0280, 0x0CD0, 0x06D0, 0x02B0, 0x0670, 0x0E70, 0x02E0, 0x0EF0, 0x06F0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0F10, 0x0E30, 0x0C10, 0x0E90, 0x0C70, 0x0870, 0x06F0, 0x0A30, 0x0800, 0x0680, 0x0A70, 0x0380, 0x0A50, 0x0A10, 0x0E10, + 0x08F0, 0x03F0, 0x0810, 0x0670, 0x0C30, 0x0E00, 0x0E00, 0x0E40, 0x0AB0, 0x06B0, 0x0CD0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0100, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + }; + short _element[8]; + short _pair[4]; + string nullArray = " "; + +dispBoB::dispBoB(PinName sda, PinName scl, PinName en): _pca(sda, scl), _en(en) { + _en = 0; + _pca.init(_loc[5]); +} + +void dispBoB::cls(void){ + for(int j = 0; j < 8; j++){ + locate(j); + _pca.bus(0x0000); + } + _cursor = 0x10; +} + +void dispBoB::locate(char pos){ + _pca.setAddress(_loc[pos]); + _cursor = pos; +} + +void dispBoB::putc(char c){ + + if(_cursor & 1){ + _element[_cursor] = _disp[c+16]; + } else { + _element[_cursor] = _disp[c-48]; + } + + int i = _cursor/2; + _pair[i] = _element[(2*i)] + _element[(2*i)+1]; + _pca.bus(_pair[i]); +} + +void dispBoB::putc(char c, char pos){ + + locate(pos); + + if(c == 32) c += 32; + if(_cursor & 1){ + _element[_cursor] = _disp[c+16]; + } else { + _element[_cursor] = _disp[c-48]; + } + + int i = _cursor/2; + _pair[i] = _element[(2*i)] + _element[(2*i)+1]; + _pca.bus(_pair[i]); +} + +void dispBoB::write(string str){ + for(int j = 5; j >= 0; j--){ + putc(toupper(str[j]), j); + } +} + +void dispBoB::scroll(string str, float speed){ + char buffer[6]; + + str.insert(0, nullArray); + str.insert(str.length(), nullArray); + + for(int k = 0; k < str.length(); k++){ + str.copy(buffer, 6, k); + write(buffer); + wait(speed); + } +} + + + + + + + + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dispBoB.h Wed Jun 29 11:23:47 2011 +0000 @@ -0,0 +1,59 @@ +//NXP PCA9635 library +//mbed Team - 28th June 2011 +//Daniel Worrall + +#ifndef MBED_DISPBOB_H +#define MBED_DISPBOB_H + +#include "mbed.h" +#include "string" +#include "PCA9635.h" +#include "ctype.h" + +class dispBoB { +public: + //constructor + dispBoB(PinName sda, PinName scl, PinName en); + + //output control + /** Clear screen + * + */ + void cls(void); + /** Set cursor position + * + * @param pos display location left to right (0-5) + */ + void locate(char pos); + /** Put an ASCII encoded character onto display at current location + * + * @param c ASCII encoded character or number (no punctuation) + */ + void putc(char c); + /** Put an ASCII encoded character onto display at specified location + * + * @param c ASCII encoded character or number + * @param pos display location lef to right (0-5) + */ + void putc(char c, char pos); + /** Write a string to the display + * + * @param str String to be displayed + */ + void write(string str); + /** Write a scrolling string (right to left) to display (no punctuation) + * + * @param str String to be displayed + * @param speed duration of each frame (seconds) + */ + void scroll(string str, float speed); + +private: + + PCA9635 _pca; + DigitalOut _en; + char _cursor; +}; + +#endif +