Thank you one more friend. I constructing a timer, which once inserted in the time display, the arduino1 sends the signal to the arduino2 to activate a relay.
But when I use the '1' (case 6 for exemple) key of the keypad display shows the number 52
My objective My code this moment
LCD display LCD display
Time ON / OFF Time ON / OFF
00:00 hh:mm 54:54 -----> 54:54
#include <EEPROM.h>
#include <virtuabotixRTC.h>
#include <Keypad.h>
// myRTC(clock, data, rst)
virtuabotixRTC myRTC(6, 7, 8);
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define CE_PIN 9
#define CSN_PIN 10
const byte FILAS = 5; // Cinco filas
const byte COLS = 4; // Cuatro columnas
char keys[FILAS][COLS] = {
{'N', 'M', '#', '*'},
{'1', '2', '3', 'U'},
{'4', '5', '6', 'D'},
{'7', '8', '9', 'C'},
{'L', '0', 'R', 'E'},
};
byte filasPins[FILAS] = {5, 4, 3, 2, 14}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {15, 8, 7, 6}; //connect to the column pinouts of the keypad
Keypad kpd = Keypad( makeKeymap(keys), filasPins, colPins, FILAS, COLS );
/*
const byte rows=4;
const byte cols=4;
char keys[rows][cols]=
{
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowpins[rows]={9,8,7,6};
byte colpins[cols]={5,4,3,2};
Keypad kpd=Keypad(makeKeymap(keys),rowpins,colpins,rows,cols);
*/
const byte slaveAddress[5] = {'R', 'x', 'A', 'A', 'A'};
char state = 1;
//char stat;
char letra;
RF24 radio(CE_PIN, CSN_PIN); // Create a Radio
char dataToSend[10] = "1";
char txNum = '0';
int addr = 0;
int Hora_ON = 0;
int Hora_OFF = 0;
int Min_ON = 0;
int Min_OFF = 0;
unsigned long currentMillis;
unsigned long prevMillis;
unsigned long txIntervalMillis = 1000;
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
void setup() {
lcd.begin(16, 2);
Serial.begin(9600);
Wire.begin();
radio.begin();
radio.setDataRate( RF24_250KBPS );
radio.setRetries(3, 5); // delay, count
radio.openWritingPipe(slaveAddress);
myRTC.setDS1302Time(00, 58, 23, 2, 17, 11, 2014);
}
void loop()
{
myRTC.updateTime();
//char key = kpd.getKey();
char key = kpd.waitForKey();
if (key)
{
switch (state) {
case 1:
switch (key) {
case 'U':
//case bUp:
lcd.clear(); Set_state(8);
break;
case 'D':
//case bDown:
lcd.clear(); Set_state(2);
break;
default:
Set_state(1);
}
break;
case 2:
//switch (CheckButton()) {
//case bChange:
switch (key) {
case 'U':
lcd.clear(); Set_state(1);
break;
case 'D':
lcd.clear(); Set_state(3);
break;
default:
Set_state(2);
}
break;
case 3:
switch (key) {
case 'R':
lcd.clear(); Hora_ON++;
lcd.setCursor(1, 0);
lcd.print ("-- Hora ON --");
lcd.setCursor(7, 1);
lcd.print (Hora_ON);
break;
case 'E':
lcd.clear(); Set_state(2);
break;
case 'D':
lcd.clear(); Set_state(4);
break;
default:
Set_state(3);
}
break;
case 4:
switch (key) {
case 'N':
lcd.clear(); Min_ON = kpd.waitForKey();
lcd.setCursor(1, 0);
lcd.print ("--- MIN ON ---");
lcd.setCursor(7, 1);
lcd.print (Min_ON);
break;
case 'E':
lcd.clear(); Set_state(3);
break;
case 'D':
lcd.clear(); Set_state(5);
break;
default:
Set_state(4);
}
break;
case 5:
switch (key) {
case 'R':
lcd.clear(); Hora_OFF++;
lcd.setCursor(1, 0);
lcd.print ("-- Hora OFF --");
lcd.setCursor(7, 1);
lcd.print (Hora_OFF);
break;
case 'E':
lcd.clear(); Set_state(4);
break;
case 'D':
lcd.clear(); Set_state(6);
break;
default:
Set_state(5);
}
break;
case 6:
switch (key) {
case 'N':
lcd.clear(); Min_OFF = kpd.waitForKey();
lcd.setCursor(1, 0);
lcd.print ("--- MIN OFF ---");
lcd.setCursor(7, 1);
lcd.print (Min_OFF);
break;
case 'E':
lcd.clear(); Set_state(5);
break;
case 'D':
lcd.clear(); Set_state(7);
break;
default:
Set_state(6);
}
break;
case 7:
switch (key) {
case 'U':
//case bUp:
lcd.clear(); Set_state(6);
break;
case 'D':
//case bDown:
lcd.clear(); Set_state(8);
break;
Set_state(7);
}
break;
case 8:
//switch (CheckButton()) {
//case bChange:
switch (key) {
case 'U':
lcd.clear(); Set_state(1);
break;
case 'D':
lcd.clear(); Set_state(7);
break;
Set_state(8);
}
break;
default:;
}
}
}
void Set_state(char index) {
state = index;
switch (state) {
case 1:
lcd.setCursor(0, 0);
lcd.print ("Irrigation TIMER");
lcd.setCursor(0, 1);
lcd.print (" By N. Duarte");
break;
case 3:
lcd.setCursor(0, 0);
lcd.print("----TIMER-ON----");
lcd.setCursor(0, 1);
lcd.print( Hora_ON, DEC);
lcd.print(" horas");
break;
case 4:
lcd.setCursor(0, 0);
lcd.print("----TIMER-ON----");
lcd.setCursor(0, 1);
lcd.print( Min_ON, DEC);
lcd.print(" minutos");
break;
case 5:
lcd.setCursor(0, 0);
lcd.print("---TIMER-OFF---");
lcd.setCursor(0, 1);
lcd.print( Hora_OFF, DEC);
lcd.print(" horas");
break;
case 6:
lcd.setCursor(0, 0);
lcd.print("---TIMER-OFF---");
lcd.setCursor(0, 1);
lcd.print( Min_OFF, DEC);
lcd.print(" minutos");
break;
case 2:
lcd.setCursor(0, 0);
lcd.print("----PROGRAMA----");
lcd.setCursor(1, 1);
lcd.print(Hora_ON, DEC);
lcd.setCursor(3, 1);
lcd.print(":");
lcd.setCursor(4, 1);
lcd.print(Min_ON, DEC);
lcd.setCursor(7, 1);
lcd.print("-->");
lcd.setCursor(11, 1);
lcd.print(Hora_OFF, DEC);
lcd.setCursor(13, 1);
lcd.print(":");
lcd.setCursor(14, 1);
lcd.print(Min_OFF, DEC);
break;
case 7:
lcd.setCursor(0, 0);
lcd.print("---TIMER-001---");
if (myRTC.hours < Hora_ON && myRTC.hours > Hora_OFF && myRTC.minutes < Min_ON && myRTC.minutes > Min_OFF) {
lcd.setCursor(0, 1);
lcd.print("Setor-01-ON");
}
else
{
lcd.setCursor(2, 1);
lcd.print("Setor-01-OFF");
}
break;
case 8:
lcd.setCursor(0, 0);
lcd.print("Modo de operacao");
break;
default:;
}
}
//====================
void send() {
if (myRTC.hours < Hora_ON && myRTC.hours > Hora_OFF && myRTC.minutes < Min_ON && myRTC.minutes > Min_OFF) {
bool rslt;
rslt = radio.write( &dataToSend, sizeof(dataToSend) );
}
}