Clemens Valens
/
cocorico_ring_demo
Simple demo showing how to control the CoCo-ri-Co LED ring.
LedMatrix.h@0:c6fa86a8f29b, 2016-06-21 (annotated)
- Committer:
- Clemo
- Date:
- Tue Jun 21 07:45:06 2016 +0000
- Revision:
- 0:c6fa86a8f29b
Demo program showing how to control the CoCo-ri-Co's LED ring.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Clemo | 0:c6fa86a8f29b | 1 | /* |
Clemo | 0:c6fa86a8f29b | 2 | * LedMatrix.h |
Clemo | 0:c6fa86a8f29b | 3 | * |
Clemo | 0:c6fa86a8f29b | 4 | * Created on: 25 january 2016 |
Clemo | 0:c6fa86a8f29b | 5 | * Author: CPV |
Clemo | 0:c6fa86a8f29b | 6 | */ |
Clemo | 0:c6fa86a8f29b | 7 | |
Clemo | 0:c6fa86a8f29b | 8 | #ifndef __LEDMATRIX_H__ |
Clemo | 0:c6fa86a8f29b | 9 | #define __LEDMATRIX_H__ |
Clemo | 0:c6fa86a8f29b | 10 | |
Clemo | 0:c6fa86a8f29b | 11 | #include "stdint.h" |
Clemo | 0:c6fa86a8f29b | 12 | |
Clemo | 0:c6fa86a8f29b | 13 | #define PIXELS (17) |
Clemo | 0:c6fa86a8f29b | 14 | #define CENTER_LED (PIXELS-1) |
Clemo | 0:c6fa86a8f29b | 15 | |
Clemo | 0:c6fa86a8f29b | 16 | #define CENTER_LED_X (P0_10) |
Clemo | 0:c6fa86a8f29b | 17 | #define CENTER_LED_Y (P0_11) |
Clemo | 0:c6fa86a8f29b | 18 | |
Clemo | 0:c6fa86a8f29b | 19 | |
Clemo | 0:c6fa86a8f29b | 20 | typedef enum |
Clemo | 0:c6fa86a8f29b | 21 | { |
Clemo | 0:c6fa86a8f29b | 22 | black = 0, |
Clemo | 0:c6fa86a8f29b | 23 | red, |
Clemo | 0:c6fa86a8f29b | 24 | green, |
Clemo | 0:c6fa86a8f29b | 25 | orange |
Clemo | 0:c6fa86a8f29b | 26 | } |
Clemo | 0:c6fa86a8f29b | 27 | LedMatrixColor_t; |
Clemo | 0:c6fa86a8f29b | 28 | |
Clemo | 0:c6fa86a8f29b | 29 | |
Clemo | 0:c6fa86a8f29b | 30 | class CLedMatrixPixel |
Clemo | 0:c6fa86a8f29b | 31 | { |
Clemo | 0:c6fa86a8f29b | 32 | public: |
Clemo | 0:c6fa86a8f29b | 33 | CLedMatrixPixel(uint8_t x, uint8_t y, LedMatrixColor_t color=black) |
Clemo | 0:c6fa86a8f29b | 34 | { |
Clemo | 0:c6fa86a8f29b | 35 | m_x = x; |
Clemo | 0:c6fa86a8f29b | 36 | m_y = y; |
Clemo | 0:c6fa86a8f29b | 37 | m_color = color; |
Clemo | 0:c6fa86a8f29b | 38 | } |
Clemo | 0:c6fa86a8f29b | 39 | |
Clemo | 0:c6fa86a8f29b | 40 | uint8_t x(void) { return m_x; } |
Clemo | 0:c6fa86a8f29b | 41 | uint8_t y(void) { return m_y; } |
Clemo | 0:c6fa86a8f29b | 42 | |
Clemo | 0:c6fa86a8f29b | 43 | LedMatrixColor_t color(void) { return m_color; } |
Clemo | 0:c6fa86a8f29b | 44 | CLedMatrixPixel& operator= (LedMatrixColor_t color) { m_color = color; return *this; } |
Clemo | 0:c6fa86a8f29b | 45 | |
Clemo | 0:c6fa86a8f29b | 46 | private: |
Clemo | 0:c6fa86a8f29b | 47 | uint8_t m_x; |
Clemo | 0:c6fa86a8f29b | 48 | uint8_t m_y; |
Clemo | 0:c6fa86a8f29b | 49 | LedMatrixColor_t m_color; |
Clemo | 0:c6fa86a8f29b | 50 | }; |
Clemo | 0:c6fa86a8f29b | 51 | |
Clemo | 0:c6fa86a8f29b | 52 | |
Clemo | 0:c6fa86a8f29b | 53 | class CLedMatrix |
Clemo | 0:c6fa86a8f29b | 54 | { |
Clemo | 0:c6fa86a8f29b | 55 | public: |
Clemo | 0:c6fa86a8f29b | 56 | CLedMatrix(void) { initialise(); } |
Clemo | 0:c6fa86a8f29b | 57 | void putPixel(uint8_t nr, LedMatrixColor_t color); |
Clemo | 0:c6fa86a8f29b | 58 | void tick(void); |
Clemo | 0:c6fa86a8f29b | 59 | |
Clemo | 0:c6fa86a8f29b | 60 | void debugLedEnable(bool enable) { m_maxPixel = enable==true? PIXELS-1 : PIXELS; } |
Clemo | 0:c6fa86a8f29b | 61 | void debugLed(LedMatrixColor_t color) |
Clemo | 0:c6fa86a8f29b | 62 | { |
Clemo | 0:c6fa86a8f29b | 63 | if (m_maxPixel!=PIXELS) setCenterLed(color); |
Clemo | 0:c6fa86a8f29b | 64 | } |
Clemo | 0:c6fa86a8f29b | 65 | |
Clemo | 0:c6fa86a8f29b | 66 | private: |
Clemo | 0:c6fa86a8f29b | 67 | void initialise(void); |
Clemo | 0:c6fa86a8f29b | 68 | void set(CLedMatrixPixel pixel, LedMatrixColor_t color); |
Clemo | 0:c6fa86a8f29b | 69 | void setCenterLed(LedMatrixColor_t color); |
Clemo | 0:c6fa86a8f29b | 70 | |
Clemo | 0:c6fa86a8f29b | 71 | uint8_t m_acitvePixel; |
Clemo | 0:c6fa86a8f29b | 72 | uint8_t m_maxPixel; |
Clemo | 0:c6fa86a8f29b | 73 | }; |
Clemo | 0:c6fa86a8f29b | 74 | |
Clemo | 0:c6fa86a8f29b | 75 | |
Clemo | 0:c6fa86a8f29b | 76 | extern DigitalOut led17g; |
Clemo | 0:c6fa86a8f29b | 77 | extern DigitalOut led17r; |
Clemo | 0:c6fa86a8f29b | 78 | |
Clemo | 0:c6fa86a8f29b | 79 | #endif /* __LEDMATRIX_H__ */ |