Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: Adafruit-GFX
RGBmatrixPanel.h
00001 #include "mbed.h" 00002 #include "Adafruit_GFX.h" 00003 00004 #ifndef _BV 00005 #define _BV(bit) (1<<(bit)) 00006 #endif 00007 00008 #ifdef DEBUG 00009 #define log_debug(format,...) std::printf(format,##__VA_ARGS__) 00010 #else 00011 #define log_debug(...) 00012 #endif 00013 00014 /** RGBmatrixPanel is class for full color LED matrix 00015 * @code 00016 #include "mbed.h" 00017 #include "RGBmatrixPanel.h" // Hardware-specific library 00018 00019 PinName ub1=p6; 00020 PinName ug1=p7; 00021 PinName ur1=p8; 00022 PinName lb2=p9; 00023 PinName lg2=p10; 00024 PinName lr2=p11; 00025 RGBmatrixPanel matrix(ur1,ug1,ub1,lr2,lg2,lb2,p12,p13,p14,p15,p16,p17,false); 00026 //RGBmatrixPanel(r1, g1, b1, r2, g2, b2, a, b, c, sclk, latch, oe, enable double_buffer); 00027 00028 int main() 00029 { 00030 matrix.begin(); 00031 while(1) { 00032 // fill the screen with 'black' 00033 matrix.fillScreen(matrix.Color333(0, 0, 0)); 00034 // draw a pixel in solid white 00035 matrix.drawPixel(0, 0, matrix.Color333(7, 7, 7)); 00036 wait_ms(500); 00037 00038 // fix the screen with green 00039 matrix.fillRect(0, 0, 32, 16, matrix.Color333(0, 7, 0)); 00040 wait_ms(500); 00041 00042 // draw a box in yellow 00043 matrix.drawRect(0, 0, 32, 16, matrix.Color333(7, 7, 0)); 00044 wait_ms(500); 00045 00046 // draw an 'X' in red 00047 matrix.drawLine(0, 0, 31, 15, matrix.Color333(7, 0, 0)); 00048 matrix.drawLine(31, 0, 0, 15, matrix.Color333(7, 0, 0)); 00049 wait_ms(500); 00050 00051 // draw a blue circle 00052 matrix.drawCircle(7, 7, 7, matrix.Color333(0, 0, 7)); 00053 wait_ms(500); 00054 00055 // fill a violet circle 00056 matrix.fillCircle(23, 7, 7, matrix.Color333(7, 0, 7)); 00057 wait_ms(500); 00058 00059 // fill the screen with 'black' 00060 matrix.fillScreen(matrix.Color333(0, 0, 0)); 00061 00062 // draw some text! 00063 matrix.setCursor(1, 0); // start at top left, with one pixel of spacing 00064 matrix.setTextSize(1); // size 1 == 8 pixels high 00065 00066 // printff each letter with a rainbow color 00067 matrix.setTextColor(matrix.Color333(7,0,0)); 00068 matrix.putc('1'); 00069 matrix.setTextColor(matrix.Color333(7,4,0)); 00070 matrix.putc('6'); 00071 matrix.setTextColor(matrix.Color333(7,7,0)); 00072 matrix.putc('x'); 00073 matrix.setTextColor(matrix.Color333(4,7,0)); 00074 matrix.putc('3'); 00075 matrix.setTextColor(matrix.Color333(0,7,0)); 00076 matrix.putc('2'); 00077 00078 matrix.setCursor(1, 9); // next line 00079 matrix.setTextColor(matrix.Color333(0,7,7)); 00080 matrix.putc('*'); 00081 matrix.setTextColor(matrix.Color333(0,4,7)); 00082 matrix.putc('R'); 00083 matrix.setTextColor(matrix.Color333(0,0,7)); 00084 matrix.putc('G'); 00085 matrix.setTextColor(matrix.Color333(4,0,7)); 00086 matrix.putc('B'); 00087 matrix.setTextColor(matrix.Color333(7,0,4)); 00088 matrix.putc('*'); 00089 wait_ms(500); 00090 } 00091 } 00092 00093 * @endcode 00094 00095 */ 00096 class RGBmatrixPanel : public Adafruit_GFX 00097 { 00098 00099 public: 00100 // Constructor for 16x32 panel: 00101 RGBmatrixPanel(PinName r1,PinName g1,PinName b1,PinName r2,PinName g2,PinName b2,PinName a,PinName b,PinName c,PinName sclk,PinName latch,PinName oe, bool dbuf); 00102 00103 // Constructor for 32x32 panel (adds 'd' pin): 00104 RGBmatrixPanel(PinName r1,PinName r2,PinName g1,PinName g2,PinName b1,PinName b2,PinName a,PinName b,PinName c,PinName d,PinName sclk, PinName latch,PinName oe,bool dbuf); 00105 00106 /** @fn void RGBmatrixPanel::begin(void) 00107 * @bref Attach a updateDisplay() to be called by the Ticker(every 100us) 00108 */ 00109 void begin(void); 00110 /** @fn void RGBmatrixPanel::drawPixel(int16_t x, int16_t y, uint16_t c) 00111 * @bref drawPixel 00112 */ 00113 virtual void drawPixel(int16_t x,int16_t y,uint16_t c); 00114 /** @fn void RGBmatrixPanel::fillScreen(uint16_t c) 00115 * @bref fillScreen 00116 * @param c fill screen 16bit color 0x0000 ~ 0xFFFF 00117 */ 00118 virtual void fillScreen(uint16_t c); 00119 /** @fn void RGBmatrixPanel::updateDisplay(void) 00120 * @param c updateDisplay\n 00121 * This method is called by the interrupt start at begin(). 00122 */ 00123 void updateDisplay (void); 00124 /** @fn void RGBmatrixPanel::swapBuffers(bool copy) 00125 * @param copy swap buffer (if you use double-buffer) 00126 */ 00127 void swapBuffers (bool copy); 00128 /** @fn void RGBmatrixPanel::dumpMatrix(void) 00129 * @bref dump to default USB Serial\n 00130 * Declaration is required to use.(#define DEBUG) 00131 */ 00132 void dumpMatrix(void); 00133 00134 uint8_t *backBuffer(void); 00135 00136 /** @fn uint16_t RGBmatrixPanel::Color333(uint8_t r, uint8_t g, uint8_t b) 00137 * @bref up convert to 16bit color from 9bit color. 00138 * @return 16bit(uint16_t) color value 00139 */ 00140 uint16_t Color333(uint8_t r, uint8_t g, uint8_t b); 00141 /** @fn uint16_t RGBmatrixPanel::Color444(uint8_t r, uint8_t g, uint8_t b) 00142 * @bref up convert to 16bit color from 12bit color. 00143 * @param r 0~7 00144 * @param g 0~7 00145 * @param b 0~7 00146 * @return 16bit(uint16_t) color value 00147 */ 00148 uint16_t Color444(uint8_t r, uint8_t g, uint8_t b); 00149 /** @fn uint16_t RGBmatrixPanel::Color888(uint8_t r, uint8_t g, uint8_t b) 00150 * @bref down convert to 16bit color from 24bit color. 00151 * @return 16bit(uint16_t) color value 00152 */ 00153 uint16_t Color888(uint8_t r, uint8_t g, uint8_t b); 00154 /** @fn uint16_t RGBmatrixPanel::Color888(uint8_t r, uint8_t g, uint8_t b, bool gflag) 00155 * @bref down convert to 16bit color from 24bit color using the gamma value table. 00156 * @return 16bit(uint16_t) color value 00157 */ 00158 uint16_t Color888(uint8_t r, uint8_t g, uint8_t b, bool gflag); 00159 /** @fn uint16_t RGBmatrixPanel::ColorHSV(long hue, uint8_t sat, uint8_t val, bool gflag) 00160 * @bref convert to 16bit color from (unsigned integer)HSV color using the gamma value table. 00161 * @param hue 0~1536(decimal value) 00162 * @param sat 0~255(decimal value) Does not make sense that it is not a multiple of 32. 00163 * @param val 0~255(decimal value) Does not make sense that it is not a multiple of 32. 00164 * @return 16bit(uint16_t) color value 00165 */ 00166 uint16_t ColorHSV(long hue, uint8_t sat, uint8_t val, bool gflag) 00167 ; 00168 /** @fn uint16_t RGBmatrixPanel::ColorHSV(float hue, float sat, float val, bool gflag) 00169 * @bref convert to 16bit color from (float)HSV color using the gamma value table. 00170 * @param hue Normalized value from 0.0 to 1.0 00171 * @param sat Normalized value from 0.0 to 1.0 00172 * @param val Normalized value from 0.0 to 1.0 00173 * @return 16bit(uint16_t) color value 00174 */ 00175 uint16_t ColorHSV(float hue, float sat, float val, bool gflag); 00176 private: 00177 uint8_t *matrixbuff[2]; 00178 uint8_t nRows; 00179 uint8_t backindex; 00180 bool swapflag; 00181 00182 // Init/alloc code common to both constructors: 00183 void init(uint8_t rows, bool dbuf); 00184 00185 BusOut _dataBus; 00186 BusOut _rowBus; 00187 DigitalOut _d,_sclk, _latch, _oe; 00188 Ticker _refresh; 00189 // Counters/pointers for interrupt handler: 00190 uint8_t row, plane; 00191 uint8_t *buffptr; 00192 };
Generated on Tue Jul 12 2022 15:51:16 by
1.7.2