Persistence of Vision (POV) made easy.
Dependencies: m3pi mbed-rtos mbed
Revision 1:38b399821b54, committed 2016-05-27
- Comitter:
- Samson Danziger
- Date:
- Fri May 27 16:51:29 2016 +0100
- Parent:
- 0:16fcd1f41239
- Child:
- 2:ba75502c4fdd
- Commit message:
- add beginnings of pov code
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/alphabet.h Fri May 27 16:51:29 2016 +0100 @@ -0,0 +1,103 @@ +#ifndef ALPHABET +#define ALPHABET + +const unsigned char font[96][6] = { + {0x00,0x00,0x00,0x00,0x00,0x00}, // + {0x2e,0x00,0x00,0x00,0x00,0x00}, // ! + {0x03,0x00,0x03,0x00,0x00,0x00}, // " + {0x0a,0x1f,0x0a,0x1f,0x0a,0x00}, // # + {0x2e,0x2a,0x6b,0x2a,0x3a,0x00}, // $ + {0x0e,0x2a,0x1e,0x08,0x3c,0x2a}, // % + {0x3e,0x2a,0x2a,0x22,0x38,0x08}, // & + {0x03,0x00,0x00,0x00,0x00,0x00}, // ' + {0x1c,0x22,0x00,0x00,0x00,0x00}, // ( + {0x22,0x1c,0x00,0x00,0x00,0x00}, // ) + {0x15,0x0e,0x04,0x0e,0x15,0x00}, // * + {0x08,0x08,0x3e,0x08,0x08,0x00}, // + + {0x60,0x00,0x00,0x00,0x00,0x00}, // , + {0x08,0x08,0x08,0x08,0x08,0x00}, // - + {0x20,0x00,0x00,0x00,0x00,0x00}, // . + {0x20,0x10,0x08,0x04,0x02,0x00}, // / + {0x3e,0x22,0x2a,0x22,0x3e,0x00}, // 0 + {0x04,0x3e,0x00,0x00,0x00,0x00}, // 1 + {0x3a,0x2a,0x2a,0x2a,0x2e,0x00}, // 2 + {0x2a,0x2a,0x2a,0x2a,0x3e,0x00}, // 3 + {0x0e,0x08,0x08,0x08,0x3e,0x00}, // 4 + {0x2e,0x2a,0x2a,0x2a,0x3a,0x00}, // 5 + {0x3e,0x2a,0x2a,0x2a,0x3a,0x00}, // 6 + {0x02,0x02,0x02,0x02,0x3e,0x00}, // 7 + {0x3e,0x2a,0x2a,0x2a,0x3e,0x00}, // 8 + {0x2e,0x2a,0x2a,0x2a,0x3e,0x00}, // 9 + {0x14,0x00,0x00,0x00,0x00,0x00}, // : + {0x34,0x00,0x00,0x00,0x00,0x00}, // ; + {0x08,0x14,0x22,0x00,0x00,0x00}, // < + {0x14,0x14,0x14,0x14,0x14,0x00}, // = + {0x22,0x14,0x08,0x00,0x00,0x00}, // > + {0x06,0x02,0x2a,0x0a,0x0e,0x00}, // ? + {0x3e,0x02,0x3a,0x2a,0x3e,0x00}, // @ + {0x3e,0x12,0x12,0x12,0x3e,0x00}, // A + {0x3e,0x2a,0x2a,0x2a,0x36,0x00}, // B + {0x3e,0x22,0x22,0x22,0x22,0x00}, // C + {0x3e,0x22,0x22,0x22,0x1c,0x00}, // D + {0x3e,0x2a,0x2a,0x2a,0x22,0x00}, // E + {0x3e,0x0a,0x0a,0x0a,0x02,0x00}, // F + {0x3e,0x22,0x2a,0x2a,0x3a,0x00}, // G + {0x3e,0x08,0x08,0x08,0x3e,0x00}, // H + {0x22,0x3e,0x22,0x00,0x00,0x00}, // I + {0x38,0x20,0x20,0x20,0x3e,0x00}, // J + {0x3e,0x08,0x08,0x14,0x22,0x00}, // K + {0x3e,0x20,0x20,0x20,0x20,0x00}, // L + {0x3e,0x04,0x38,0x04,0x3e,0x00}, // M + {0x3e,0x04,0x08,0x10,0x3e,0x00}, // N + {0x3e,0x22,0x22,0x22,0x3e,0x00}, // O + {0x3e,0x0a,0x0a,0x0a,0x0e,0x00}, // P + {0x3e,0x22,0x72,0x22,0x3e,0x00}, // Q + {0x3e,0x0a,0x0a,0x1a,0x2e,0x00}, // R + {0x2e,0x2a,0x2a,0x2a,0x3a,0x00}, // S + {0x02,0x02,0x3e,0x02,0x02,0x00}, // T + {0x1e,0x20,0x20,0x20,0x1e,0x00}, // U + {0x0e,0x10,0x20,0x10,0x0e,0x00}, // V + {0x3e,0x10,0x0e,0x10,0x3e,0x00}, // W + {0x22,0x14,0x08,0x14,0x22,0x00}, // X + {0x02,0x04,0x38,0x04,0x02,0x00}, // Y + {0x3a,0x2a,0x2a,0x2a,0x2e,0x00}, // Z + {0x3e,0x22,0x00,0x00,0x00,0x00}, // [ + {0x3f,0x21,0x3f,0x00,0x00,0x00}, // "\" + {0x22,0x3e,0x00,0x00,0x00,0x00}, // ] + {0x0c,0x1e,0x3c,0x1e,0x0c,0x00}, // ^ + {0x20,0x20,0x20,0x20,0x20,0x00}, // _ + {0x1c,0x3e,0x3e,0x3e,0x1c,0x00}, // ` + {0x3c,0x24,0x24,0x24,0x3c,0x20}, // a + {0x3e,0x24,0x24,0x24,0x3c,0x00}, // b + {0x3c,0x24,0x24,0x24,0x24,0x00}, // c + {0x3c,0x24,0x24,0x24,0x3e,0x00}, // d + {0x3c,0x24,0x34,0x2c,0x24,0x00}, // e + {0x08,0x3e,0x0a,0x0a,0x00,0x00}, // f + {0x1c,0x54,0x54,0x54,0x7c,0x00}, // g + {0x3e,0x04,0x04,0x04,0x3c,0x00}, // h + {0x3a,0x00,0x00,0x00,0x00,0x00}, // i + {0x7a,0x00,0x00,0x00,0x00,0x00}, // j + {0x3e,0x08,0x14,0x22,0x00,0x00}, // k + {0x02,0x3e,0x00,0x00,0x00,0x00}, // l + {0x3c,0x04,0x3c,0x04,0x3c,0x00}, // m + {0x3c,0x04,0x04,0x04,0x3c,0x00}, // n + {0x3c,0x24,0x24,0x24,0x3c,0x00}, // o + {0x7c,0x24,0x24,0x24,0x3c,0x00}, // p + {0x3c,0x24,0x24,0x24,0x7c,0x00}, // q + {0x3c,0x04,0x04,0x04,0x00,0x00}, // r + {0x24,0x2c,0x34,0x24,0x00,0x00}, // s + {0x04,0x3e,0x24,0x24,0x00,0x00}, // t + {0x3c,0x20,0x20,0x20,0x3c,0x00}, // u + {0x0c,0x10,0x20,0x10,0x0c,0x00}, // v + {0x3c,0x20,0x3c,0x20,0x3c,0x00}, // w + {0x24,0x24,0x18,0x24,0x24,0x00}, // x + {0x1c,0x50,0x50,0x50,0x7c,0x00}, // y + {0x24,0x34,0x2c,0x24,0x00,0x00}, // z + {0x08,0x3e,0x22,0x00,0x00,0x00}, // { + {0x1c,0x22,0x22,0x22,0x1c,0x00}, // | + {0x22,0x3e,0x08,0x00,0x00,0x00}, // } + {0x01,0x01,0x01,0x00,0x00,0x00}, // ~ + {0x00,0x00,0x00,0x00,0x00,0x00} +}; + +#endif //ALPHABET
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/m3pi_pov.cpp Fri May 27 16:51:29 2016 +0100 @@ -0,0 +1,61 @@ +#include "m3pi_pov.h" +#include "alphabet.h" + +#define SPIN_SPEED 1.0 +#define PIXEL_TIME 0.002 + +BusOut _leds; +m3pi m3pi; + +int pov_display = 1; // flag for pov display while loop + +pov::pov(PinName l1, PinName l2, PinName l3, PinName l4, PinName l5, + PinName l6, PinName l7, PinName l8) { + _leds(l8, l7, l6, l5, l4, l3, l2, l1); +} + +pov:::pov() { + _leds(p20, p19, p18, p17, p16, p15, p14, p13); +} + + +void pov::init(void) { + m3pi.right(SPIN_SPEED); +} + +void pov::init(int spin) { + if (spin < 0) { + m3pi.left(); + } else { + m3pi.right(); + } +} + +void pov::stop(void) { + pov_display = 0; + m3pi.stop(); +} + +void pov::display(char* text) { + pov_display = 1; + while (pov_display) { + for (char* it = text; *it; ++it) { + char[] arr = _get_char_arr(it); + for (int i = 0; i < 6; i++) { + char a = arr[i]; + _leds = (int) a; + wait(PIXEL_TIME); + } + } + } +} + +char[] pov::_get_char_arr(char c) { + int arr_loc = c - 32; + return font[arr_loc]; +} + + + + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/m3pi_pov.h Fri May 27 16:51:29 2016 +0100 @@ -0,0 +1,63 @@ +#ifndef M3PI_POV +#define M3PI_POV + +#include "mbed.h" + +class pov: public Stream { + +public: + + /** Create the pov object connected to default pins. + * + */ + pov(); + + /** Create the pov object connected to specific pins. + * + * @param l1 LED 1. Default is p13. + * @param l2 LED 2. Default is p14. + * @param l3 LED 3. Default is p15. + * @param l4 LED 4. Default is p16. + * @param l5 LED 5. Default is p17. + * @param l6 LED 6. Default is p18. + * @param l7 LED 7. Default is p19. + * @param l8 LED 8. Default is p20. + */ + pov(PinName l1, PinName l2, PinName l3, PinName l4, PinName l5, PinName l6, + PinName l7, PinName l8); + + /** Initialise the POV display. Default right spin. + * + */ + void init(void); + + /** Initialise the POV display. + * + * @param spin A negative number for a spin to the left, a positive + * number or 0 for a spin to the right. + */ + void init(int spin); + + /** Stop the POV display. + * + */ + void stop(void); + + /** Display a string on the POV display. + * + * @param text Text to display. + */ + void display(char* text); + +private: + + /** Get a the int array representation of a letter. + * + * @param c The character to get the int array representation for. + */ + char[] _get_char_arr(char c); + +}; + + +#endif //M3PI_POV