#include <LiquidCrystal_I2C.h> //アドレス0x27 16文字2行の液晶 LiquidCrystal_I2C lcd(0x27, 16, 2); void setup() { lcd.init(); lcd.backlight(); } void loop() { static int i; if (i < 100) i++; else i = 0; bar(0, i); delay(500); } void bar(int line, int per) { char buff[17]; sprintf(buff, " %3d%%", per); for (int i = 0; i < (per / 10); i++) { buff[i] = 0xFF; } lcd.setCursor(0, line); lcd.print(buff); }
#include <LiquidCrystal_I2C.h> byte data_1[4][8] = {{ 0b00010000, 0b00010000, 0b00010000, 0b00010000, 0b00010000, 0b00010000, 0b00010000, 0b00010000, }, { 0b00011000, 0b00011000, 0b00011000, 0b00011000, 0b00011000, 0b00011000, 0b00011000, 0b00011000, }, { 0b00011100, 0b00011100, 0b00011100, 0b00011100, 0b00011100, 0b00011100, 0b00011100, 0b00011100, }, { 0b00011110, 0b00011110, 0b00011110, 0b00011110, 0b00011110, 0b00011110, 0b00011110, 0b00011110, } }; //アドレス0x27 16文字2行の液晶 LiquidCrystal_I2C lcd(0x27, 16, 2); void setup() { lcd.init(); lcd.createChar(0x00, data_1[0]); lcd.createChar(0x01, data_1[1]); lcd.createChar(0x02, data_1[2]); lcd.createChar(0x03, data_1[3]); lcd.backlight(); lcd.setCursor(0, 0); lcd.write(byte(0x00)); lcd.write(byte(0x01)); lcd.write(byte(0x02)); lcd.write(byte(0x03)); lcd.write(byte(0xFF)); } void loop() { }
#include <LiquidCrystal_I2C.h> //アドレス0x27 16文字2行の液晶 LiquidCrystal_I2C lcd(0x27, 16, 2); byte data_1[4][8] = {{ 0b00010000, 0b00010000, 0b00010000, 0b00010000, 0b00010000, 0b00010000, 0b00010000, 0b00010000, }, { 0b00011000, 0b00011000, 0b00011000, 0b00011000, 0b00011000, 0b00011000, 0b00011000, 0b00011000, }, { 0b00011100, 0b00011100, 0b00011100, 0b00011100, 0b00011100, 0b00011100, 0b00011100, 0b00011100, }, { 0b00011110, 0b00011110, 0b00011110, 0b00011110, 0b00011110, 0b00011110, 0b00011110, 0b00011110, } }; void setup() { lcd.init(); lcd.createChar(0x01, data_1[0]); lcd.createChar(0x02, data_1[1]); lcd.createChar(0x03, data_1[2]); lcd.createChar(0x04, data_1[3]); lcd.backlight(); } void loop() { static int i; if (i < 100) i++; else i = 0; bar(0, i); delay(500); } void bar(int line, int per) { int map[10] = {0x20, 0x20, 0x01, 0x01, 0x02, 0x02, 0x03, 0x03, 0x04, 0x04}; char buff[17]; sprintf(buff, " %3d%%", per); int i = 0; for (; i < (per / 10); i++) { buff[i] = 0xFF; } buff[i] = map[per % 10]; lcd.setCursor(0, line); lcd.print(buff); }