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: EthernetInterface NTPClient mbed-rtos mbed
LedPanel.cpp
00001 /** 00002 * Matrix16x16 LEDPanel library 00003 * 00004 * @author Junichi Katsu 00005 * @version 1.0 00006 * @date 02-April-2015 00007 * 00008 */ 00009 00010 #include "mbed.h" 00011 #include "LedPanel.h" 00012 #include "LedPanel_GFX.h" 00013 00014 LedPanel::LedPanel(I2C *i2c): _i2c(i2c), LedPanel_GFX(16, 16) 00015 { 00016 00017 } 00018 00019 void LedPanel::setBrightness(uint8_t b) 00020 { 00021 if (b > 15) b = 15; 00022 00023 uint8_t c = 0xE0 | b; 00024 char foo[1]; 00025 00026 foo[0] = c; 00027 00028 _i2c->write(i2c_addr[0], foo, 1); 00029 _i2c->write(i2c_addr[1], foo, 1); 00030 } 00031 00032 void LedPanel::blinkRate(uint8_t b) 00033 { 00034 if (b > 3) b = 0; 00035 00036 uint8_t c = HT16K33_BLINK_CMD | HT16K33_BLINK_DISPLAYON | (b << 1); 00037 00038 char foo[1]; 00039 foo[0] = c; 00040 00041 _i2c->write(i2c_addr[0], foo, 1); 00042 _i2c->write(i2c_addr[1], foo, 1); 00043 } 00044 00045 void LedPanel::begin(uint8_t _addr0,uint8_t _addr1) 00046 { 00047 i2c_addr[0] = _addr0 << 1; 00048 i2c_addr[1] = _addr1 << 1; 00049 00050 char foo[1]; 00051 foo[0] = 0x21; 00052 00053 _i2c->write(i2c_addr[0], foo, 1); 00054 _i2c->write(i2c_addr[1], foo, 1); 00055 00056 blinkRate(HT16K33_BLINK_OFF); 00057 00058 setBrightness(15); 00059 } 00060 00061 void LedPanel::writeDisplay(void) 00062 { 00063 char foo[2][17]; 00064 foo[0][0] = 0x00; 00065 foo[1][0] = 0x00; 00066 00067 int j = 0; 00068 for (uint8_t i=1; i<=16; i+=2) 00069 { 00070 for(uint8_t k=0; k < 2 ; k++) 00071 { 00072 int x = displaybuffer[j + k*8] & 0xFF; 00073 foo[k][i] = x; 00074 x = displaybuffer[j + k*8] >> 8; 00075 foo[k][i+1] = x; 00076 } 00077 j++; 00078 } 00079 _i2c->write(i2c_addr[0], foo[0], 17); 00080 _i2c->write(i2c_addr[1], foo[1], 17); 00081 } 00082 00083 void LedPanel::clear(void) 00084 { 00085 for (uint8_t i=0; i<16; i++) 00086 { 00087 displaybuffer[i] = 0; 00088 } 00089 } 00090 00091 void LedPanel::drawPixel(int16_t x, int16_t y, uint16_t color) 00092 { 00093 if ((y < 0) || (y >= 16)) return; 00094 if ((x < 0) || (x >= 16)) return; 00095 00096 if (color) 00097 { 00098 displaybuffer[y] |= 1 << x; 00099 } 00100 else 00101 { 00102 displaybuffer[y] &= ~(1 << x); 00103 } 00104 } 00105 00106 void LedPanel::Scroll(int16_t x, int16_t y) 00107 { 00108 bool bit[16]; 00109 for (uint8_t i=0; i<16; i++) 00110 { 00111 bit[i] = false; 00112 00113 if( (displaybuffer[i] & 0x8000) != 0 ) 00114 { 00115 bit[i] = true; 00116 } 00117 displaybuffer[i] <<= 1; 00118 00119 if( bit[i] == true ) 00120 { 00121 displaybuffer[i] |= 1; 00122 } 00123 } 00124 }
Generated on Thu Jul 14 2022 17:34:26 by
1.7.2