Components and supplies
Graphic LCD 128x64 STN LED Backlight
Grove - Buzzer - Piezo
Arduino Nano
PS/2 Port
Keyboard
3 mm LED: Yellow
Tools and machines
Soldering kit
Apps and platforms
Arduino IDE
Project description
Code
code
cpp
...
1/* Arduino morse Encoder 2 * 3 *PS2Keyboard library example 4 PS2Keyboard now requries both pins specified for begin() 5 keyboard.begin(data_pin, irq_pin); 6 7 Valid irq pins: 8 Arduino Uno: 2, 3 9 Arduino Due: All pins, except 13 (LED) 10 Arduino Mega: 2, 3, 18, 19, 20, 21 11 Teensy 3.0: All pins, except 13 (LED) 12 Teensy 2.0: 5, 6, 7, 8 13 Teensy 1.0: 0, 1, 2, 3, 4, 6, 7, 16 14 Teensy++ 2.0: 0, 1, 2, 3, 18, 19, 36, 37 15 Teensy++ 1.0: 0, 1, 2, 3, 18, 19, 36, 37 16 Sanguino: 2, 10, 11 17 18 for more information you can read the original wiki in arduino.cc 19 at http://www.arduino.cc/playground/Main/PS2Keyboard 20 or http://www.pjrc.com/teensy/td_libs_PS2Keyboard.html 21 22 Like the Original library and example this is under LGPL license. 23 24 Modified by Cuninganreset@gmail.com on 2010-03-22 25 Modified by Paul Stoffregen <paul@pjrc.com> June 2010 26*/ 27 28#include <PS2Keyboard.h> 29#include <U8g2lib.h> 30#include "Lewis.h" 31#include <TimerOne.h> 32 33 34U8G2_ST7565_ERC12864_1_4W_SW_SPI u8g2 ( U8G2_R0, /* scl=*/ 13 , /* si=*/ 11 , /* cs=*/ 10 , /* rs=*/ 9 , /* rse=*/ 8 ) ; 35 36const int DataPin = 3; 37const int IRQpin = 2; 38 39char* znak; 40char* wiersz[10]; //char workline* 41char* wiersz1[10]; //top line char* 42int wiersz_M[10]; //workline in ASCII code 43int wiersz_M1[10]; //top line in ASCII code 44byte k; 45int d, e, i; //helper variables 46byte isnm = 7; //number of words per minute 47char isnm_str[2]; 48byte kursor; 49const byte index_key = 48; //number of characters in the array 50const char* KeyChar[index_key] = { 51"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s", 52"t","u","v","w","x","y","z","0","1","2","3","4","5","6","7","8","9"," ", 53"!","(",")","+",",","-",".","/","=","?","_"}; 54const int ASCII[index_key] = { 55 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115, 56116,117,118,119,120,121,122, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 32, 57 33, 40, 41, 43, 44, 45, 46, 47, 61, 63, 95}; 58 59PS2Keyboard keyboard; 60Lewis Morse; 61 62 63void setup() { 64 delay(1000); 65 keyboard.begin(DataPin, IRQpin); 66 Serial.begin(9600); 67 // u8g2.begin (); 68 // u8g2.setContrast(20); 69 //Morse.begin(rx_pin, tx_pin, words_per_minute, use_interrupts) 70 71 Morse.begin(7,7, isnm, true); 72 u8g2.begin (); 73 u8g2.setContrast(40); 74 //use the TimerOne library for a 100Hz timer interrupt 75 Timer1.initialize(1000); 76 Timer1.attachInterrupt(MorseISR); 77} 78 79void loop() { 80 PS2(); //reading characters from the keyboard 81 if (znak == "enter" ) { Send_Morse();} //sending the line to broadcast 82 Display(); //display the line 83 Display(); //display the line 84} 85 86void PS2() { 87 if (keyboard.available()) { 88 // read the next key 89 char c = keyboard.read(); 90 d = int(c); 91 // check for some of the special keys 92 if (c == PS2_ENTER) { 93 znak ="enter"; 94// } else if (c == PS2_TAB) { 95// Serial.print("[Tab]"); 96// } else if (c == PS2_ESC) { 97// Serial.print("[ESC]"); 98 } else if (c == PS2_PAGEDOWN) { 99 isnm--; 100 if (isnm < 1 ) {isnm = 1;} 101 102 Morse.begin(7,7, isnm, true); 103 } else if (c == PS2_PAGEUP) { 104 isnm++; 105 if (isnm > 30) {isnm = 30;} 106 Morse.begin(7,7, isnm, true); 107 108 // } else if (c == PS2_LEFTARROW) { 109 // Serial.print("[Left]"); 110 // } else if (c == PS2_RIGHTARROW) { 111 // Serial.print("[Right]"); 112 // } else if (c == PS2_UPARROW) { 113 // Serial.print("[Up]"); 114 // } else if (c == PS2_DOWNARROW) { 115 // Serial.print("[Down]"); 116 } else if (c == PS2_DELETE) { 117 znak = "back"; 118 i--; 119 znak = " "; 120 wiersz[i] = znak; 121 wiersz_M[i] = d; 122 } else { 123 // otherwise substitute a regular letter 124 getKeyChar(); //converting char to char* 125 wiersz[i] = znak; 126 wiersz_M[i] = d; 127 if (i > 9) {i = -1;} 128 if (znak == "enter"){i = -1;} 129 if (znak != "back" && znak != "enter") {i++;} //increase character counter 130 } 131 } 132} 133 134void Display() { //display data on the LCD 135 kursor++; 136 if (kursor >20){ kursor = 0;} 137 sprintf(isnm_str,"%d", isnm); //converting a number to a string 138 u8g2.firstPage(); 139 do { 140 u8g2.setFont(u8g2_font_10x20_tr); 141 u8g2.drawStr(0, 15, "Morse"); 142 u8g2.drawStr(75, 15, isnm_str); 143 u8g2.drawStr(98, 15, "w/m"); 144 for (k = 0; k < 10; k++){ 145 u8g2.drawStr(k*10, 40, wiersz1[k] ); 146 u8g2.drawStr(k*10, 60, wiersz[k] ); 147 } 148 if (kursor<15){u8g2.drawStr(i*10, 60, "_" );} //display the cursor 149 if (kursor>5){u8g2.drawStr(i*10, 60, " " );} //cursor blinking 150 } while ( u8g2.nextPage() ); 151} 152 153void Send_Morse(){ 154 znak = " "; 155 for (int k = 0; k < 10; k++) { 156 wiersz1[k] = " "; //cash 157 wiersz1[k] = wiersz[k]; //rewriting characters from the working line to the top 158 wiersz[k] = " "; //delete work line 159 wiersz_M1[k] = 32; //delete ASCII top line 160 wiersz_M1[k] = wiersz_M[k]; //rewrite ASCII from the working line to the top line 161 wiersz_M[k] = 32; //delete ASCII worklineroboczego 162 } 163 for (int k = 1; k < 10; k++){ 164 e = wiersz_M1[k]; 165 Morse.write(e); //morse the contents of the top line 166 } 167 i = 0; 168} 169 170void MorseISR(){ 171 Morse.timerISR(); //function triggered by interrupts (keyboard) 172} 173 174void getKeyChar() { //converting a key code into a letter and an ASCII code 175 for (k = 0; k <= index_key; k++){ 176 if (ASCII[k] == d) { znak = KeyChar[k];} //convert key code to letter 177 } 178 k = 0; 179}
Downloadable files
schematic with LED
...
with Led.png
Schematic with Relay
...
with Relay module.png
Comments
Only logged in users can leave comments