Persistence of Vision (POV) made easy.
Dependencies: m3pi mbed-rtos mbed
m3pi_pov.cpp@1:38b399821b54, 2016-05-27 (annotated)
- Committer:
- Samson Danziger
- Date:
- Fri May 27 16:51:29 2016 +0100
- Revision:
- 1:38b399821b54
add beginnings of pov code
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Samson Danziger |
1:38b399821b54 | 1 | #include "m3pi_pov.h" |
Samson Danziger |
1:38b399821b54 | 2 | #include "alphabet.h" |
Samson Danziger |
1:38b399821b54 | 3 | |
Samson Danziger |
1:38b399821b54 | 4 | #define SPIN_SPEED 1.0 |
Samson Danziger |
1:38b399821b54 | 5 | #define PIXEL_TIME 0.002 |
Samson Danziger |
1:38b399821b54 | 6 | |
Samson Danziger |
1:38b399821b54 | 7 | BusOut _leds; |
Samson Danziger |
1:38b399821b54 | 8 | m3pi m3pi; |
Samson Danziger |
1:38b399821b54 | 9 | |
Samson Danziger |
1:38b399821b54 | 10 | int pov_display = 1; // flag for pov display while loop |
Samson Danziger |
1:38b399821b54 | 11 | |
Samson Danziger |
1:38b399821b54 | 12 | pov::pov(PinName l1, PinName l2, PinName l3, PinName l4, PinName l5, |
Samson Danziger |
1:38b399821b54 | 13 | PinName l6, PinName l7, PinName l8) { |
Samson Danziger |
1:38b399821b54 | 14 | _leds(l8, l7, l6, l5, l4, l3, l2, l1); |
Samson Danziger |
1:38b399821b54 | 15 | } |
Samson Danziger |
1:38b399821b54 | 16 | |
Samson Danziger |
1:38b399821b54 | 17 | pov:::pov() { |
Samson Danziger |
1:38b399821b54 | 18 | _leds(p20, p19, p18, p17, p16, p15, p14, p13); |
Samson Danziger |
1:38b399821b54 | 19 | } |
Samson Danziger |
1:38b399821b54 | 20 | |
Samson Danziger |
1:38b399821b54 | 21 | |
Samson Danziger |
1:38b399821b54 | 22 | void pov::init(void) { |
Samson Danziger |
1:38b399821b54 | 23 | m3pi.right(SPIN_SPEED); |
Samson Danziger |
1:38b399821b54 | 24 | } |
Samson Danziger |
1:38b399821b54 | 25 | |
Samson Danziger |
1:38b399821b54 | 26 | void pov::init(int spin) { |
Samson Danziger |
1:38b399821b54 | 27 | if (spin < 0) { |
Samson Danziger |
1:38b399821b54 | 28 | m3pi.left(); |
Samson Danziger |
1:38b399821b54 | 29 | } else { |
Samson Danziger |
1:38b399821b54 | 30 | m3pi.right(); |
Samson Danziger |
1:38b399821b54 | 31 | } |
Samson Danziger |
1:38b399821b54 | 32 | } |
Samson Danziger |
1:38b399821b54 | 33 | |
Samson Danziger |
1:38b399821b54 | 34 | void pov::stop(void) { |
Samson Danziger |
1:38b399821b54 | 35 | pov_display = 0; |
Samson Danziger |
1:38b399821b54 | 36 | m3pi.stop(); |
Samson Danziger |
1:38b399821b54 | 37 | } |
Samson Danziger |
1:38b399821b54 | 38 | |
Samson Danziger |
1:38b399821b54 | 39 | void pov::display(char* text) { |
Samson Danziger |
1:38b399821b54 | 40 | pov_display = 1; |
Samson Danziger |
1:38b399821b54 | 41 | while (pov_display) { |
Samson Danziger |
1:38b399821b54 | 42 | for (char* it = text; *it; ++it) { |
Samson Danziger |
1:38b399821b54 | 43 | char[] arr = _get_char_arr(it); |
Samson Danziger |
1:38b399821b54 | 44 | for (int i = 0; i < 6; i++) { |
Samson Danziger |
1:38b399821b54 | 45 | char a = arr[i]; |
Samson Danziger |
1:38b399821b54 | 46 | _leds = (int) a; |
Samson Danziger |
1:38b399821b54 | 47 | wait(PIXEL_TIME); |
Samson Danziger |
1:38b399821b54 | 48 | } |
Samson Danziger |
1:38b399821b54 | 49 | } |
Samson Danziger |
1:38b399821b54 | 50 | } |
Samson Danziger |
1:38b399821b54 | 51 | } |
Samson Danziger |
1:38b399821b54 | 52 | |
Samson Danziger |
1:38b399821b54 | 53 | char[] pov::_get_char_arr(char c) { |
Samson Danziger |
1:38b399821b54 | 54 | int arr_loc = c - 32; |
Samson Danziger |
1:38b399821b54 | 55 | return font[arr_loc]; |
Samson Danziger |
1:38b399821b54 | 56 | } |
Samson Danziger |
1:38b399821b54 | 57 | |
Samson Danziger |
1:38b399821b54 | 58 | |
Samson Danziger |
1:38b399821b54 | 59 | |
Samson Danziger |
1:38b399821b54 | 60 | |
Samson Danziger |
1:38b399821b54 | 61 |