Hello
I wonder if someone here can help me to add a automatic code to this sketch.
Sketch is working i use a keypad but only button 5 and 7 is in use.
When i power on arduino,i want automatic hold down the button 5 for 4 seconds and then released,without i push the button manually down.
(data.relay1 must be activated for 4 seconds and then not activated,without i push the button manually down)
It is absolutely very easy to add that to the sketch but I do not know how to do it,sow i can pay 12 dollar through Paypal. ![]()
send me a PM
#include <Keypad.h> // Keypad
#include <EasyTransfer.h> // Rs-422/485
EasyTransfer Transfer; // Rs-422/485
//******************************************************************************
// Keypad
//******************************************************************************
const byte ROWS = 4; // four rows
const byte COLS = 3; // three columns
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[ROWS] = {5, 4, 3, 2}; // connect to the row pinouts of the keypad
byte colPins[COLS] = {8, 7, 6}; // connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
//****************************************************************************
// Setup
//****************************************************************************
boolean enable = true;
boolean enabled = true;
boolean relay_1 = false;
boolean relay_2 = false;
unsigned long lastSend = 0;
unsigned long currentTime;
int sendInterval = 75;
unsigned long previousMillis = 0;
unsigned long interval = 1500;
int ledPin = 9;
int ledState = LOW;
//****************************************************************************
// Rs-422/485 - receiver Setup
//****************************************************************************
struct rovData
{
int relay1;
int relay2;
}data;
//***************************************************************************
void setup()
//***************************************************************************
{
Serial.begin(57600);
Transfer.begin(details(data), &Serial);
pinMode(ledPin, OUTPUT);
keypad.addEventListener(keypadEvent); // Keypad
}
//**************************************************************************
void loop()
//**************************************************************************
{
unsigned long currentMillis = millis();
if(currentMillis - previousMillis > interval)
{
previousMillis = currentMillis;
if(ledState == LOW)
{
ledState = HIGH;
}
else
{
ledState = LOW;
}
digitalWrite(ledPin, ledState);
}
char key = keypad.getKey();
}
//*************************************************************************
inline void keypadEvent(KeypadEvent key){
//*************************************************************************
switch (keypad.getState()){
case PRESSED:
switch (key){
case '5': data.relay1 = 1; break;
case '7': data.relay2 = 1; break;
}
break;
case RELEASED:
switch (key){
case '5': data.relay1 = 0; break;
case '7': data.relay2 = 0; break;
}
break;
case HOLD:
break;
}
}
//*********************************************************************************
inline void readkey()
//*********************************************************************************
{
currentTime = millis();
if(currentTime - lastSend > sendInterval)
{
lastSend = currentTime;
if(enable == true)
{
Transfer.sendData();
}
}
}
keypad_code.ino (3.32 KB)