Этюд: Мультик на LCD 1602

Нет ответов
arduinec
Offline
Зарегистрирован: 01.09.2015

В дисплее LCD 1602 есть 8 ячеек для пользовательских символов, в них можно загружать любые графические символы размером 5x8. Если все 8 ячеек расположить рядом и периодически менять в них загружаемые элементы, то можно делать даже небольшие мультики.

В нижеприведённом счетче мультик из 8 кадров (из 5 уникальных снимков):

#include <LiquidCrystal.h>

LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

#define msDelay 1000

byte k10[8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
byte k11[8] = { 0x03, 0x07, 0x07, 0x07, 0x07, 0x03, 0x01, 0x03 };
byte k12[8] = { 0x18, 0x1C, 0x1C, 0x1C, 0x1C, 0x18, 0x10, 0x18 };
byte k13[8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
byte k14[8] = { 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
byte k15[8] = { 0x09, 0x11, 0x01, 0x01, 0x02, 0x04, 0x08, 0x08 };
byte k16[8] = { 0x12, 0x11, 0x10, 0x10, 0x08, 0x04, 0x02, 0x02 };
byte k17[8] = { 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };

byte k20[8] = { 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x00 };
byte k21[8] = { 0x00, 0x00, 0x1E, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F };
byte k22[8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18 };
byte k23[8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
byte k24[8] = { 0x00, 0x00, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00 };
byte k25[8] = { 0x0E, 0x13, 0x03, 0x01, 0x03, 0x0C, 0x08, 0x08 };
byte k26[8] = { 0x06, 0x01, 0x00, 0x10, 0x10, 0x08, 0x0C, 0x03 };
byte k27[8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };

byte k30[8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x07, 0x07 };
byte k31[8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x1C, 0x1D };
byte k32[8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x10 };
byte k33[8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
byte k34[8] = { 0x07, 0x07, 0x03, 0x01, 0x02, 0x02, 0x04, 0x00 };
byte k35[8] = { 0x1E, 0x1C, 0x1E, 0x17, 0x03, 0x0F, 0x10, 0x08 };
byte k36[8] = { 0x00, 0x00, 0x00, 0x00, 0x10, 0x1B, 0x06, 0x00 };
byte k37[8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };

byte k40[8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
byte k41[8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03 };
byte k42[8] = { 0x00, 0x00, 0x0F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F };
byte k43[8] = { 0x00, 0x00, 0x00, 0x10, 0x10, 0x10, 0x10, 0x00 };
byte k44[8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
byte k45[8] = { 0x0C, 0x10, 0x00, 0x01, 0x01, 0x02, 0x06, 0x18 };
byte k46[8] = { 0x0E, 0x19, 0x18, 0x10, 0x18, 0x06, 0x02, 0x02 };
byte k47[8] = { 0x00, 0x00, 0x10, 0x08, 0x00, 0x00, 0x00, 0x00 };

byte k50[8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
byte k51[8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x01 };
byte k52[8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x07, 0x17 };
byte k53[8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x1C, 0x1C };
byte k54[8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
byte k55[8] = { 0x00, 0x00, 0x00, 0x00, 0x01, 0x1B, 0x0C, 0x00 };
byte k56[8] = { 0x0F, 0x07, 0x0F, 0x1D, 0x18, 0x1E, 0x01, 0x02 };
byte k57[8] = { 0x1C, 0x1C, 0x18, 0x10, 0x08, 0x08, 0x04, 0x00 };

void setup()
{
  lcd.begin(16, 2);
  lcd.noCursor();

  lcd.setCursor(0, 0);
  lcd.print(" \1\2\3 \1\2\3 \1\2\3 \1\2\3");
  lcd.setCursor(0, 1);
  lcd.print("\4\5\6\7\4\5\6\7\4\5\6\7\4\5\6\7");

  lcd.setCursor(0, 0);  lcd.write(byte(0));
  lcd.setCursor(4, 0);  lcd.write(byte(0));
  lcd.setCursor(8, 0);  lcd.write(byte(0));
  lcd.setCursor(12, 0); lcd.write(byte(0));
}
 
void loop()
{
  lcd.createChar(0, k10); lcd.createChar(1, k11);
  lcd.createChar(2, k12); lcd.createChar(3, k13);
  lcd.createChar(4, k14); lcd.createChar(5, k15);
  lcd.createChar(6, k16); lcd.createChar(7, k17);
  delay(msDelay);

  lcd.createChar(0, k20); lcd.createChar(1, k21);
  lcd.createChar(2, k22); lcd.createChar(3, k23);
  lcd.createChar(4, k24); lcd.createChar(5, k25);
  lcd.createChar(6, k26); lcd.createChar(7, k27);
  delay(msDelay);

  lcd.createChar(0, k30); lcd.createChar(1, k31);
  lcd.createChar(2, k32); lcd.createChar(3, k33);
  lcd.createChar(4, k34); lcd.createChar(5, k35);
  lcd.createChar(6, k36); lcd.createChar(7, k37);
  delay(msDelay);

  lcd.createChar(0, k20); lcd.createChar(1, k21);
  lcd.createChar(2, k22); lcd.createChar(3, k23);
  lcd.createChar(4, k24); lcd.createChar(5, k25);
  lcd.createChar(6, k26); lcd.createChar(7, k27);
  delay(msDelay);

  lcd.createChar(0, k10); lcd.createChar(1, k11);
  lcd.createChar(2, k12); lcd.createChar(3, k13);
  lcd.createChar(4, k14); lcd.createChar(5, k15);
  lcd.createChar(6, k16); lcd.createChar(7, k17);
  delay(msDelay);

  lcd.createChar(0, k40); lcd.createChar(1, k41);
  lcd.createChar(2, k42); lcd.createChar(3, k43);
  lcd.createChar(4, k44); lcd.createChar(5, k45);
  lcd.createChar(6, k46); lcd.createChar(7, k47);
  delay(msDelay);

  lcd.createChar(0, k50); lcd.createChar(1, k51);
  lcd.createChar(2, k52); lcd.createChar(3, k53);
  lcd.createChar(4, k54); lcd.createChar(5, k55);
  lcd.createChar(6, k56); lcd.createChar(7, k57);
  delay(msDelay);

  lcd.createChar(0, k40); lcd.createChar(1, k41);
  lcd.createChar(2, k42); lcd.createChar(3, k43);
  lcd.createChar(4, k44); lcd.createChar(5, k45);
  lcd.createChar(6, k46); lcd.createChar(7, k47);
  delay(msDelay);
}

Более удобный для редактирования код здесь:

#include <LiquidCrystal.h>

LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

#define msDelay 1000

byte k10[8] =
{
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000
};
byte k11[8] =
{
  B00011,
  B00111,
  B00111,
  B00111,
  B00111,
  B00011,
  B00001,
  B00011
};
byte k12[8] =
{
  B11000,
  B11100,
  B11100,
  B11100,
  B11100,
  B11000,
  B10000,
  B11000
};
byte k13[8] =
{
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000
};
byte k14[8] =
{
  B00000,
  B00001,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000
};
byte k15[8] =
{
  B01001,
  B10001,
  B00001,
  B00001,
  B00010,
  B00100,
  B01000,
  B01000
};
byte k16[8] =
{
  B10010,
  B10001,
  B10000,
  B10000,
  B01000,
  B00100,
  B00010,
  B00010
};
byte k17[8] =
{
  B00000,
  B10000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000
};

byte k20[8] =
{
  B00000,
  B00000,
  B00000,
  B00001,
  B00001,
  B00001,
  B00001,
  B00000
};
byte k21[8] =
{
  B00000,
  B00000,
  B11110,
  B11111,
  B11111,
  B11111,
  B11111,
  B11111
};
byte k22[8] =
{
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B11000
};
byte k23[8] =
{
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000
};
byte k24[8] =
{
  B00000,
  B00000,
  B00001,
  B00010,
  B00000,
  B00000,
  B00000,
  B00000
};
byte k25[8] =
{
  B01110,
  B10011,
  B00011,
  B00001,
  B00011,
  B01100,
  B01000,
  B01000
};
byte k26[8] =
{
  B00110,
  B00001,
  B00000,
  B10000,
  B10000,
  B01000,
  B01100,
  B00011
};
byte k27[8] =
{
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000
};

byte k30[8] =
{
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00011,
  B00111,
  B00111
};
byte k31[8] =
{
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B11000,
  B11100,
  B11101
};
byte k32[8] =
{
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B01100,
  B10000
};
byte k33[8] =
{
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000
};
byte k34[8] =
{
  B00111,
  B00111,
  B00011,
  B00001,
  B00010,
  B00010,
  B00100,
  B00000
};
byte k35[8] =
{
  B11110,
  B11100,
  B11110,
  B10111,
  B00011,
  B01111,
  B10000,
  B01000
};
byte k36[8] =
{
  B00000,
  B00000,
  B00000,
  B00000,
  B10000,
  B11011,
  B00110,
  B00000
};
byte k37[8] =
{
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000
};

byte k40[8] =
{
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000
};
byte k41[8] =
{
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00011
};
byte k42[8] =
{
  B00000,
  B00000,
  B01111,
  B11111,
  B11111,
  B11111,
  B11111,
  B11111
};
byte k43[8] =
{
  B00000,
  B00000,
  B00000,
  B10000,
  B10000,
  B10000,
  B10000,
  B00000
};
byte k44[8] =
{
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000
};
byte k45[8] =
{
  B01100,
  B10000,
  B00000,
  B00001,
  B00001,
  B00010,
  B00110,
  B11000
};
byte k46[8] =
{
  B01110,
  B11001,
  B11000,
  B10000,
  B11000,
  B00110,
  B00010,
  B00010
};
byte k47[8] =
{
  B00000,
  B00000,
  B10000,
  B01000,
  B00000,
  B00000,
  B00000,
  B00000
};

byte k50[8] =
{
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000
};
byte k51[8] =
{
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00110,
  B00001
};
byte k52[8] =
{
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00011,
  B00111,
  B10111
};
byte k53[8] =
{
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B11000,
  B11100,
  B11100
};
byte k54[8] =
{
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000
};
byte k55[8] =
{
  B00000,
  B00000,
  B00000,
  B00000,
  B00001,
  B11011,
  B01100,
  B00000
};
byte k56[8] =
{
  B01111,
  B00111,
  B01111,
  B11101,
  B11000,
  B11110,
  B00001,
  B00010
};
byte k57[8] =
{
  B11100,
  B11100,
  B11000,
  B10000,
  B01000,
  B01000,
  B00100,
  B00000
};

void setup()
{
  lcd.begin(16, 2);
  lcd.noCursor();

  lcd.setCursor(0, 0);
  lcd.print(" \1\2\3 \1\2\3 \1\2\3 \1\2\3");
  lcd.setCursor(0, 1);
  lcd.print("\4\5\6\7\4\5\6\7\4\5\6\7\4\5\6\7");

  lcd.setCursor(0, 0);
  lcd.write(byte(0));
  lcd.setCursor(4, 0);
  lcd.write(byte(0));
  lcd.setCursor(8, 0);
  lcd.write(byte(0));
  lcd.setCursor(12, 0);
  lcd.write(byte(0));
}
 
void loop()
{
  lcd.createChar(0, k10);
  lcd.createChar(1, k11);
  lcd.createChar(2, k12);
  lcd.createChar(3, k13);
  lcd.createChar(4, k14);
  lcd.createChar(5, k15);
  lcd.createChar(6, k16);
  lcd.createChar(7, k17);
  delay(msDelay);

  lcd.createChar(0, k20);
  lcd.createChar(1, k21);
  lcd.createChar(2, k22);
  lcd.createChar(3, k23);
  lcd.createChar(4, k24);
  lcd.createChar(5, k25);
  lcd.createChar(6, k26);
  lcd.createChar(7, k27);
  delay(msDelay);

  lcd.createChar(0, k30);
  lcd.createChar(1, k31);
  lcd.createChar(2, k32);
  lcd.createChar(3, k33);
  lcd.createChar(4, k34);
  lcd.createChar(5, k35);
  lcd.createChar(6, k36);
  lcd.createChar(7, k37);
  delay(msDelay);

  lcd.createChar(0, k20);
  lcd.createChar(1, k21);
  lcd.createChar(2, k22);
  lcd.createChar(3, k23);
  lcd.createChar(4, k24);
  lcd.createChar(5, k25);
  lcd.createChar(6, k26);
  lcd.createChar(7, k27);
  delay(msDelay);

  lcd.createChar(0, k10);
  lcd.createChar(1, k11);
  lcd.createChar(2, k12);
  lcd.createChar(3, k13);
  lcd.createChar(4, k14);
  lcd.createChar(5, k15);
  lcd.createChar(6, k16);
  lcd.createChar(7, k17);
  delay(msDelay);

  lcd.createChar(0, k40);
  lcd.createChar(1, k41);
  lcd.createChar(2, k42);
  lcd.createChar(3, k43);
  lcd.createChar(4, k44);
  lcd.createChar(5, k45);
  lcd.createChar(6, k46);
  lcd.createChar(7, k47);
  delay(msDelay);

  lcd.createChar(0, k50);
  lcd.createChar(1, k51);
  lcd.createChar(2, k52);
  lcd.createChar(3, k53);
  lcd.createChar(4, k54);
  lcd.createChar(5, k55);
  lcd.createChar(6, k56);
  lcd.createChar(7, k57);
  delay(msDelay);

  lcd.createChar(0, k40);
  lcd.createChar(1, k41);
  lcd.createChar(2, k42);
  lcd.createChar(3, k43);
  lcd.createChar(4, k44);
  lcd.createChar(5, k45);
  lcd.createChar(6, k46);
  lcd.createChar(7, k47);
  delay(msDelay);
}

Если к пользовательским символам добавить обычные, а также применять скроллинг, то можно делать более продолжительные мульфильмы.

Можно даже конкурс на форуме устроить на лучший мульфильм :)