#include <LiquidCrystal.h>
bool buzOn = false; // HIGH или LOW на выводе «+» зуммера
unsigned long time0 = 0;
unsigned long repeat_duration = 0;
int f = 1000; // Частота
//bool is_stop
unsigned long one_second = 800000;
int counter = 0;
int amount = 45;
struct Note {
int f;
unsigned long duration;
String text;
};
byte sym_Ya[8] = {B00000,B01111,B10001,B10001,B01111,B00101,B01001,B10001}; // Буква "Я"0
byte sym_Sh[8] =
{B00000,B10101,B10101,B10101,B10101,B10101,B11111,B00000}; // Буква "Ш"1
byte sym_Sch[8] =
{B00000,B10101,B10101,B10101,B10101,B10101,B11111,B00001}; // Буква "Щ"2
byte sym_J[8] = {B00000,B10101,B10101,B10101,B01110,B10101,B10101,B10101}; // Буква "Ж"3
byte sym_Yu[8] = {B00000,B10010,B10101,B10101,B11101,B10101,B10101,B10010}; // Буква "Ю"4
byte sym_G[8] = {B00000,B11111,B10001,B10000,B10000,B10000,B10000,B10000}; // Буква "Г"5
byte sym_L[8] =
{B00000,B01111,B00101,B00101,B00101,B00101,B10101,B01001}; // Буква "Л"6
byte sym_D[8] = {B01111,B00101,B00101,B01001,B10001,B11111,B10001,B10001}; // Буква "Д"7
//ч 209
//46
struct Note notes[46] = {
{ 392, one_second/2, "ROC-" },
{ 523, one_second, "Cu-" },
{ 392, one_second/2 + one_second/8, "0 " },
{ 440, one_second/4, "CB0-" },
{ 494, one_second, "2EH-" },
{ 329, one_second/2, "HA-" },
{ 329, one_second/2, "0 " },
{ 440, one_second, "HA-" },
{ 392, one_second/2 + one_second/8, "1A " },
{ 349, one_second/4, "7EP-" },
{ 392, one_second, "3A-" },
{ 261, one_second/2, "BA " },
{ 261, one_second/2, "ROC-" },
{ 294, one_second, "CN-" },
{ 294, one_second/2 + one_second/8, "0 " },
{ 330, one_second/4, "64-" },
{ 349, one_second, "BN-" },
{ 349, one_second/2 + one_second/8, "MA-" },
{ 392, one_second/4, "0 " },
{ 440, one_second, "HA-" },
{ 494, one_second/2 + one_second/8, "1A " },
{ 523, one_second/4, "CTPA-" },
{ 587, one_second + one_second/8, "HA " },
{ 392, one_second/2, "MO" },
{ 659, one_second, "5Y-" },
{ 587, one_second/2 + one_second/8, "SA-" },
{ 523, one_second/4, "0 " },
{ 587, one_second, "BO-" },
{ 494, one_second/2, "60 " },
{ 392, one_second/2, "BE-" },
{ 523, one_second, "6N-" },
{ 494, one_second/2 + one_second/8, "KA-" },
{ 440, one_second/4, "0 " },
{ 494, one_second, "C6A-" },
{ 330, one_second/2, "BA " },
{ 330, one_second/2, "TBO-" },
{ 440, one_second, "E " },
{ 392, one_second/2 + one_second/8, "7OC-" },
{ 330, one_second/4, "TO-" },
{ 392, one_second, "0HN-" },
{ 261, one_second/2 + one_second/8, "E " },
{ 261, one_second/4, "NA " },
{ 523, one_second, "BCE " },
{ 494, one_second/2 + one_second/8, "BRE-" },
{ 440, one_second/4, "ME-" },
{ 392, one_second*2, "HA!" }
};
unsigned long current_note = notes[0].duration;
//LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
void setup() {
pinMode(13,OUTPUT);
digitalWrite(13, LOW);
Serial.begin(9600);
lcd.begin(16, 2); // Указываем, что дисплей 1602
lcd.createChar(0, sym_Ya);
lcd.createChar(1, sym_Sh);
lcd.createChar(2, sym_Sch);
lcd.createChar(3, sym_J);
lcd.createChar(4, sym_Yu);
lcd.createChar(5, sym_G);
lcd.createChar(6, sym_L);
lcd.createChar(7, sym_D);
lcd.clear();
writeText(notes[0].text);
}
void loop() {
if (counter <= amount){
play();
}
}
void play() {
if (micros() < current_note){
int t_2_us = 500000 / notes[counter].f;
if (micros() - time0 > t_2_us)
{
time0 = micros();
buzOn = !buzOn;
if (buzOn) digitalWrite(13, HIGH);
else digitalWrite(13, LOW);
}
} else {
//lcd.clear();
delay(20);
//Serial.println(notes[counter].text);
//lcd.print(notes[counter].text);
bool isNewLine = writeText(notes[counter+1].text);
if(isNewLine) {
writeText(notes[counter+1].text);
}
counter++;
//Serial.print(counter);
current_note = current_note + notes[counter].duration;
}
}
int counter_stroke = 0;
int counter_line = 0;
bool writeText(String text) {
for(int i = 0; i < text.length(); i++) {
counter_stroke++;
if(counter_stroke == 16) {
counter_line++;
counter_stroke = 0;
lcd.setCursor(0, 1);
if(counter_line == 2) {
counter_line = 0;
lcd.setCursor(0, 0);
lcd.clear();
return true;
}
}
int globalId = -1;
switch(text[i]) {
case '0'://Я
globalId = 0;
break;
case '1'://Ш
globalId = 1;
break;
case '2'://Щ
globalId = 2;
break;
case '3'://Ж
globalId = 3;
break;
case '4'://Ю
globalId = 4;
break;
case '5'://Г
globalId = 5;
break;
case 'S'://Ч
globalId = 209;
break;
case '6'://Л
globalId = 6;
break;
case '7'://Д
globalId = 7;
break;
}
if(globalId != -1) {
lcd.write((byte)globalId);
} else {
lcd.print(text[i]);
}
}
return false;
}