hello arduino friends.
i am trying to make two arduino based devices that sends text one to an other !
until now everything is ok !
i have a 4x4 keypad and a 16x2 lcd connected and they both work fine !
the input method is like a normal sms creation, a few presses over a keypad changes the character on the lcd and if the time between the two presses is more that 1 seccond it moves the cursor to the next step !
how can i send those chars over rf ?
and are there any schematics that i can download to test ?
#include <Time.h>
#include <Keypad.h>
#include <ctype.h>
#include <MorseEnDecoder.h>
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const byte ROWS = 4; //four rows
const byte COLS = 4; //three columns
// Define the keymaps. The blank spot (lower left) is the space character.
char alphaKeys[ROWS][COLS] = {
{'a','d','g','A'},
{'j','m','p','B'},
{'s','v','y','C'},
{' ','.',',','D'}
};
char numberKeys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{' ','0','.','D'}
};
boolean alpha = false; // Start with the numeric keypad.
char* keypadMap = (alpha == true) ? makeKeymap(alphaKeys) : makeKeymap(numberKeys);
byte rowPins[ROWS] = {
45, 47, 49, 51}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {
37, 39, 41, 43}; //connect to the column pinouts of the keypad
//create a new Keypad
Keypad keypad = Keypad(keypadMap, rowPins, colPins, sizeof(rowPins), sizeof(colPins));
unsigned long startTime;
const byte ledPin = 13;
int i = -1;
int j = 0;
int k=0;
long puss=0;
long puss2=1;
int flag=0;
int flag2=1;
int flag3=0;
int functionKey = 0;
String messageComplete[34];
char message1[ ] = " ";
char message[ ] = " ";
int morseOutPin = 13;
int morseInPin = 7;
char temp;
morseDecoder morseInput(morseInPin, MORSE_KEYER, MORSE_ACTIVE_LOW);
morseEncoder morseOutput(morseOutPin);
void setup(){
lcd.begin(16, 2); // Starts the LCD library and sets 2 coloumns of 16 chars each
Serial.begin(9600); // begins the serial communication over usb with the computer at 9600 bauds
pinMode(ledPin, OUTPUT); // sets the led on the arduino as an output device
digitalWrite(ledPin, LOW); // Turns the LED on.
keypad.addEventListener(keypadEvent); // Add an event listener.
keypad.setHoldTime(500);
morseInput.setspeed(64); // sets the input to 64 chars per minute
morseOutput.setspeed(64); // sets the output to 64 chars per minute
};
void loop(){
char key = keypad.getKey();
if (alpha && millis()-startTime>100) { // Flash the LED if we are using the letter keymap.
digitalWrite(ledPin,!digitalRead(ledPin));
startTime = millis();
}
};
//transmition protocol
void transmit(){
}
// Take care of some special events.
void keypadEvent(KeypadEvent key) {
static char virtKey = NO_KEY; // Stores the last virtual key press. (Alpha keys only)
static char physKey = NO_KEY; // Stores the last physical key press. (Alpha keys only)
static char buildStr[12];
static byte buildCount;
static byte pressCount;
switch (keypad.getState())
{
case PRESSED:
if (flag2==0 & isalpha(key)) { // Pressed the same key again...
puss=millis();
if (puss != puss2){
if ((puss - puss2)>1000){
flag3=1;
}
else {
flag3=0;
}
puss2=millis();
}
}
if (isalpha(key)) { // This is a letter key so we're using the letter keymap.
if (physKey != key) { // New key so start with the first of 3 characters.
pressCount = 0;
virtKey = key;
physKey = key;
flag2 = 1;
}
else { // Pressed the same key again...
if (flag3==1){
virtKey++; // so select the next character on that key.
pressCount++; // Tracks how many times we press the same key.
flag2 = 0;
flag = 0;
}
else {
virtKey++; // so select the next character on that key.
pressCount++; // Tracks how many times we press the same key.
i--;
flag2 = 0;
flag=1;
}
}
}
if (pressCount > 2) { // Last character reached so cycle back to start.
pressCount = 0;
virtKey = key;
}
if (isdigit(key) || key == ' ' || key == '.' || key == ',') {
virtKey = key ;
}
if (key == 'A'){
key = 'A';
functionKey = 1;
}
if (key == 'C'){
functionKey = 1;
lcd.begin(16, 2);
i=0;
j=0;
i--;
i--;
virtKey = 'C';
}
if (key == 'D'){
functionKey = 1;
virtKey= 'D';
if (i<0 & j==1){
i=16;
j=0;
}
lcd.setCursor(i,j);
lcd.print(" ");
lcd.print(" ");
i--;
i--;
}
if (i > 14 & j == 0){
i = -1;
j = 1;
} else if (i == 15 & j == 1){
i = -1;
j = 0;
}
else {
i++;
}
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
lcd.setCursor(i,j); // prosexe apo edo !!!!!!!!!!!!!!!!!!!!!!!
if (functionKey == 0){
lcd.print(virtKey); // Used for testing.
if (j==1){
message1[i] = virtKey;
} else {
message[i] = virtKey;
} // mexri edo !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
}
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//to message 1 einai i kato grammi tis lcd kai to message einai i epano
// pos mporo na ta kano auta binary ?
break;
case HOLD:
if (key == 'B') { // Toggle between keymaps.
virtKey='B';
functionKey = 1;
if (alpha == true) { // We are currently using a keymap with letters
keypad.begin(*numberKeys); // and want to change to numbers.
alpha = false;
digitalWrite(ledPin, LOW);
}
else { // Or, we are currently using a keymap with numbers
keypad.begin(*alphaKeys); // and want to change to letters.
alpha = true;
}
}
break;
case RELEASED:
break;
} // end switch-case
} // end keypad events