#include #define ADRS 0x38 class I2C7seg { public: void begin(); void write(byte,byte); void print(byte,byte); }; void I2C7seg::begin() { Wire.begin(); Wire.beginTransmission(ADRS); Wire.write((uint8_t)0x80); Wire.write((uint8_t)0xC8); Wire.endTransmission(); Wire.beginTransmission(ADRS); Wire.write((uint8_t)0x20); Wire.write((uint8_t)0x00); Wire.endTransmission(); } void I2C7seg::write(byte adr, byte numx) { Wire.beginTransmission(ADRS); Wire.write((uint8_t)0x80); Wire.write(adr); Wire.endTransmission(); Wire.beginTransmission(ADRS); Wire.write((uint8_t)0x40); Wire.write(numx); Wire.endTransmission(); } void I2C7seg::print(byte col, byte bitdata) { // // Addresses by digit position: // // 15 13 11 0F 0D 0B 09 07 47 45 43 41 3F 3D 3B 39 (37 Lo4bit: % yen kWh kg(CO2)) // 17 19 1B 1D 1F 21 23 25 27 29 2B 2D 2F 31 33 35 (37 Hi4bit: % yen kWh kg(CO2)) // // Binary digit order = BcbadegfX // (Swap 4 bits when address between 15 to 35) // // --a-- // f b // --g-- // e c // --d-- // // [X] addresses // 1D: Genarating by wind power // 1F: AVR saving // 27: Now // 29: Last month // 2B: Year // 2D: Month // 2F: Last year same month // 31: Day // 33: Last year // 35: Month forecast // int adr = (col %= 32) * 2; if( col < 8 ) adr = 0x15 - adr; else if( col < 16 ) adr = 0x57 - adr; else adr -= 0x09; if( adr >= 0x15 && adr <= 0x35 ) bitdata = (bitdata << 4) | (bitdata >> 4); this->write(adr,bitdata); } PROGMEM const char digitsOn7seg[] = { //BcbadegfX B11111010, // 0 B11000000, // 1 B01111100, // 2 B11110100, // 3 B11000110, // 4 B10110110, // 5 B10111110, // 6 B11100000, // 7 B11111110, // 8 B11110110, // 9 B11101110, // A B10011110, // b B00111010, // C B11011100, // d B00111110, // E B00101110, // F }; I2C7seg lcd = I2C7seg(); void setup() { lcd.begin(); } void loop() { static byte pos = 0; static byte data37 = 0; if( (pos & 0x1F) == 0 ) { for (byte i=0x07; i<=0x47; i++) lcd.write(i,0xFF); delay(5000); for (byte i=0x07; i<=0x47; i++) lcd.write(i,0); for (byte i=1; i>0; i<<=1) { lcd.write( 0x37, i ); delay(500); } lcd.write( 0x37, 0xFF ); } byte num = (pos - (pos/16)) % 16; // 012..DEF FED..CDE EF0..BCD, D.. byte data = pgm_read_byte(digitsOn7seg+num); lcd.print( pos, data ); delay(250); lcd.print( pos, data|1 ); pos++; delay(250); }