#include <PS2Keyboard.h>
#include <U8g2lib.h>
#include "Lewis.h"
#include <TimerOne.h>
U8G2_ST7565_ERC12864_1_4W_SW_SPI u8g2 ( U8G2_R0, 13 , 11 , 10 , 9 , 8 ) ;
const int DataPin = 3;
const int IRQpin = 2;
char* znak;
char* wiersz[10];
char* wiersz1[10];
int wiersz_M[10];
int wiersz_M1[10];
byte k;
int d, e, i;
byte isnm = 7;
char isnm_str[2];
byte kursor;
const byte index_key = 48;
const char* KeyChar[index_key] = {
"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s",
"t","u","v","w","x","y","z","0","1","2","3","4","5","6","7","8","9"," ",
"!","(",")","+",",","-",".","/","=","?","_"};
const int ASCII[index_key] = {
97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,
116,117,118,119,120,121,122, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 32,
33, 40, 41, 43, 44, 45, 46, 47, 61, 63, 95};
PS2Keyboard keyboard;
Lewis Morse;
void setup() {
delay(1000);
keyboard.begin(DataPin, IRQpin);
Serial.begin(9600);
Morse.begin(7,7, isnm, true);
u8g2.begin ();
u8g2.setContrast(40);
Timer1.initialize(1000);
Timer1.attachInterrupt(MorseISR);
}
void loop() {
PS2();
if (znak == "enter" ) { Send_Morse();}
Display();
Display();
}
void PS2() {
if (keyboard.available()) {
char c = keyboard.read();
d = int(c);
if (c == PS2_ENTER) {
znak ="enter";
} else if (c == PS2_PAGEDOWN) {
isnm--;
if (isnm < 1 ) {isnm = 1;}
Morse.begin(7,7, isnm, true);
} else if (c == PS2_PAGEUP) {
isnm++;
if (isnm > 30) {isnm = 30;}
Morse.begin(7,7, isnm, true);
} else if (c == PS2_DELETE) {
znak = "back";
i--;
znak = " ";
wiersz[i] = znak;
wiersz_M[i] = d;
} else {
getKeyChar();
wiersz[i] = znak;
wiersz_M[i] = d;
if (i > 9) {i = -1;}
if (znak == "enter"){i = -1;}
if (znak != "back" && znak != "enter") {i++;}
}
}
}
void Display() {
kursor++;
if (kursor >20){ kursor = 0;}
sprintf(isnm_str,"%d", isnm);
u8g2.firstPage();
do {
u8g2.setFont(u8g2_font_10x20_tr);
u8g2.drawStr(0, 15, "Morse");
u8g2.drawStr(75, 15, isnm_str);
u8g2.drawStr(98, 15, "w/m");
for (k = 0; k < 10; k++){
u8g2.drawStr(k*10, 40, wiersz1[k] );
u8g2.drawStr(k*10, 60, wiersz[k] );
}
if (kursor<15){u8g2.drawStr(i*10, 60, "_" );}
if (kursor>5){u8g2.drawStr(i*10, 60, " " );}
} while ( u8g2.nextPage() );
}
void Send_Morse(){
znak = " ";
for (int k = 0; k < 10; k++) {
wiersz1[k] = " ";
wiersz1[k] = wiersz[k];
wiersz[k] = " ";
wiersz_M1[k] = 32;
wiersz_M1[k] = wiersz_M[k];
wiersz_M[k] = 32;
}
for (int k = 1; k < 10; k++){
e = wiersz_M1[k];
Morse.write(e);
}
i = 0;
}
void MorseISR(){
Morse.timerISR();
}
void getKeyChar() {
for (k = 0; k <= index_key; k++){
if (ASCII[k] == d) { znak = KeyChar[k];}
}
k = 0;
}
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.