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.
Fork of RGB_Matrix by
RGB_Matrix.h
00001 /* mbed RGB Matrix Library 00002 * Written for Nucleo-F446RE, v1.0, 03-10-2015 00003 * 00004 * Copyright (c) 2013-2015 JackB, cstyles 00005 * 00006 * Permission is hereby granted, free of charge, to any person obtaining a copy 00007 * of this software and associated documentation files (the "Software"), to deal 00008 * in the Software without restriction, including without limitation the rights 00009 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00010 * copies of the Software, and to permit persons to whom the Software is 00011 * furnished to do so, subject to the following conditions: 00012 * 00013 * The above copyright notice and this permission notice shall be included in 00014 * all copies or substantial portions of the Software. 00015 * 00016 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00017 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00018 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00019 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00020 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00021 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00022 * THE SOFTWARE. 00023 */ 00024 00025 #ifndef MBED_RGB_MATRIX_H 00026 #define MBED_RGB_MATRIX_H 00027 00028 #include "mbed.h" 00029 #include "math.h" 00030 //#include "GraphicsDisplay.h" 00031 00032 /** RGB_Matrix calculation class 00033 * 00034 * Example: 00035 * @code 00036 * // Continuously sweep the RGB_Matrix through it's full range 00037 * #include "mbed.h" 00038 * #include "RGB_Matrix.h" 00039 * 00040 * RGB_Matrix myRGB_Matrix(LED1,LED2,LED3); 00041 * 00042 * int main() { 00043 * myRGB_Matrix.SetS(1.0); 00044 * myRGB_Matrix.SetV(1.0); 00045 * while(1) { 00046 * for(int i=0; i<100; i++) { 00047 * myRGB_Matrix.SetH((float)i/100.0); 00048 * myRGB_Matrix.RGB_Matrix_to_RGB(); 00049 * wait(0.01); 00050 * } 00051 * } 00052 * } 00053 * @endcode 00054 */ 00055 00056 #define ROWS 16 00057 #define PLANES 7 00058 #define WIDTH 64 00059 #define HEIGHT 32 00060 #define PIXELS 2048 // WIDTH * HEIGHT 00061 #define DBUF true 00062 #define LANDSCAPE_T 0 00063 #define PORTRAIT_L 1 00064 #define LANDSCAPE_B 2 00065 #define PORTRAIT_R 3 00066 00067 #define BYTESPERCHAR 0 00068 #define FONTWIDTH 1 00069 #define FONTHEIGHT 2 00070 #define BYTESPERLINE 3 00071 00072 #define INTTIME 0.00012 // 0.0003 is slowest, 0.00007 is fastest, Nr2 0.000001 is fastest 00073 00074 #define RGB(r,g,b) (((r&0xF8)<<8)|((g&0xFC)<<3)|((b&0xF8)>>3)) //5 red | 6 green | 5 blue 00075 00076 00077 /* some RGB color definitions 00078 00079 RRRR RGGG GGGB BBBB 00080 */ 00081 #define Black 0x0000 /* 0, 0, 0 */ 00082 #define Navy 0x000F /* 0, 0, 128 */ 00083 #define DarkBlue 0x000F /* 0, 0, 255 */ 00084 #define DarkGreen 0x03E0 /* 0, 128, 0 */ 00085 #define DarkCyan 0x03EF /* 0, 128, 128 */ 00086 #define Maroon 0x7800 /* 128, 0, 0 */ 00087 #define Purple 0x780F /* 128, 0, 128 */ 00088 #define Olive 0x7BE0 /* 128, 128, 0 */ 00089 #define LightGrey 0xC618 /* 192, 192, 192 */ 00090 #define Grey 0x7BEF /* 128, 128, 128 */ 00091 #define DarkGrey 0x4208 /* 64, 64, 64 01000 010000 01000 */ 00092 #define Blue 0x001F /* 0, 0, 255 */ 00093 #define Green 0x07E0 /* 0, 255, 0 */ 00094 #define Cyan 0x07FF /* 0, 255, 255 */ 00095 #define Red 0xF800 /* 255, 0, 0 */ 00096 #define Magenta 0xF81F /* 255, 0, 255 */ 00097 #define Yellow 0xFFE0 /* 255, 255, 0 */ 00098 #define White 0xFFFF /* 255, 255, 255 11111 111111 11111 */ 00099 #define Orange 0xFD20 /* 255, 165, 0 11111 101001 00000 */ 00100 #define GreenYellow 0xAFE5 /* 173, 255, 47 10101 111111 00101 */ 00101 00102 00103 class RGB_Matrix 00104 //class RGB_Matrix : public GraphicsDisplay 00105 { 00106 public: 00107 00108 /** Create a RGB_Matrix object 00109 * 00110 * @param void 00111 */ 00112 RGB_Matrix(PinName Pin_R1, PinName Pin_R2, PinName Pin_G1, PinName Pin_G2, 00113 PinName Pin_B1, PinName Pin_B2, 00114 PinName Pin_CLK, PinName Pin_LAT, PinName Pin_OE, 00115 PinName Pin_A, PinName Pin_B, PinName Pin_C, PinName Pin_D); 00116 00117 void Init(void); 00118 00119 void swap(int16_t &x, int16_t &y); 00120 uint16_t rgbToColor(uint8_t R, uint8_t G, uint8_t B); 00121 00122 void drawPixel2(int16_t x, int16_t y, uint16_t c); 00123 void drawPixel(int16_t x, int16_t y, uint16_t c); 00124 00125 void set_font(unsigned char* f); 00126 00127 void character(int x, int y, int c); 00128 00129 int putc(int value); 00130 void printString(char *string); 00131 void printStringCenter(char *string); 00132 00133 void foreground(uint16_t colour); 00134 void background(uint16_t colour); 00135 int width(); 00136 int height(); 00137 void SetOrientation(uint8_t orientation); 00138 void locate(uint8_t x, uint8_t y); 00139 void locatePixelX(uint8_t x); 00140 void locatePixelY(uint8_t y); 00141 00142 int columns(); 00143 int rows(); 00144 00145 void setDisplayBuffer(uint8_t Buffer); 00146 void setWriteBuffer(uint8_t Buffer); 00147 00148 void updateDisplay(void); 00149 void updateDisplay2(void); 00150 00151 private: 00152 00153 DigitalOut _Pin_R1; 00154 DigitalOut _Pin_R2; 00155 DigitalOut _Pin_G1; 00156 DigitalOut _Pin_G2; 00157 DigitalOut _Pin_B1; 00158 DigitalOut _Pin_B2; 00159 DigitalOut _Pin_CLK; 00160 DigitalOut _Pin_LAT; 00161 DigitalOut _Pin_OE; 00162 DigitalOut _Pin_A; 00163 DigitalOut _Pin_B; 00164 DigitalOut _Pin_C; 00165 DigitalOut _Pin_D; 00166 00167 Ticker Update; 00168 00169 // Counters/pointers for interrupt handler: 00170 uint8_t row, plane, bufferDisplay, bufferWrite; 00171 // uint8_t PixelValueR1, PixelValueG1, PixelValueB1; 00172 // uint8_t PixelValueR2, PixelValueG2, PixelValueB2; 00173 uint8_t *buffptr; 00174 // volatile uint8_t backindex; 00175 // volatile bool swapflag; 00176 00177 uint8_t *matrixbuff[2]; 00178 // uint8_t pixelbuff0[WIDTH*HEIGHT*PLANES]; 00179 // uint8_t pixelbuff1[WIDTH*ROWS*PLANES]; 00180 00181 unsigned char* font; 00182 uint8_t char_x; 00183 uint8_t char_y; 00184 uint16_t _foreground, _background; 00185 uint8_t _orientation; 00186 00187 // Code for matrix pixel pwm 00188 00189 00190 00191 }; 00192 00193 #endif 00194
Generated on Sat Jul 16 2022 11:10:24 by
1.7.2
