Yes here you go, i have not had much time to make all the changes you have suggested but other than the blocking that happens when the blinkLED function runs, the program works pretty good.
There is a Pixel RGB connected to A0, i do not have either the relays or the motors hooked up as i need transistors to run them. So its just a keypad, led, and blynk app. Im not sure of a good way to draw up a diagram other than by hand but. The pixel uses a 220 ohm resistor to connect the data in to A0 and 7 pins from the keypad are used with digital pins D0 - D6. D7 and DAC1 are used to output high or low when i need to.
#include <neopixel.h>
#include <blynk.h>
#include "Blynk/BlynkTimer.h"
#include <Keypad_Particle.h>
//required to link photon to Blynk
char auth[] = "";
//pixel stuff
#define PIXEL_PIN A0
#define PIXEL_COUNT 1
#define PIXEL_TYPE WS2811
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
//Colors for rgb
int PixelColorYellow = strip.Color(90, 40, 0);
int PixelColorRed = strip.Color (50 , 0 , 0);
int PixelColorGreen = strip.Color(0, 50 , 0);
int OFF = strip.Color(0,0,0);
int rgbColor;
//setups keypad
const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = { //Assigns a value to each key on the keypad
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[ROWS] = {6, 5, 4, 3}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {2, 1, 0}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
BlynkTimer timer;
String lockstatus = "Ready...";
String code;
char key;//key from keypad as char
int keypadlockout(0);//Variable so the keypad can be locked out
int notcorrect(0);//Counts how many times incorrect password is enterd
int casenumber(0);//for case number in switch statement
int numblinks(0);//Arguments for led function to tell how many times to blink
int blinkrate(0);//messing around with progresive blink rates when blinkLED funtion is called
bool repeatactionunlock(false);//Keeps track if action has already been done
bool repeatactionlock(false);//Keeps track if action has already been done
void myTimerEvent()
{
Blynk.virtualWrite(V5, lockstatus); // writes to a virtual pin the lock status
Blynk.virtualWrite(V1, code); //writes to a virtual pin the current code being entered (for debugging)
Blynk.virtualWrite(V2, notcorrect);//debugging for incorrect code count
}
bool pinValue;
BLYNK_WRITE(V0){
pinValue = param.asInt();
}
//timer function, can be called and set the delay. softDelay(10000) = delay of 10 seconds
inline void softDelay(uint32_t t) {
for (uint32_t ms = millis(); millis() - ms < t; Particle.process());
}
void setup(){
Serial.begin(9600);
delay(5000);
Blynk.begin(auth); //required to link blynk to photon
timer.setInterval(1000L, myTimerEvent);
strip.begin();
}
//Function to be called when the led needs to be flashed, takes in the rbgColor, and numb of blinks
double i = 1.00;
void blinkLED(int rgbColor, int numblinks, int blinkrate){
for (numblinks; numblinks > 0; numblinks--){ // numblinks, blinks led numblinks times, with 1 second total on off time.
i = i + .01;
blinkrate = blinkrate/(i);
strip.setPixelColor(0, rgbColor);//turns LED on green for duration of unlocking
strip.show();
softDelay(blinkrate);//led on for whatever blink rate is set to in ms
strip.setPixelColor(0, OFF);
strip.show();
softDelay(blinkrate);//led off for whatever blink rate is set to in ms
Serial.print(casenumber);
}
i = 1.00;
}
//Function when led needs to be solid, takes in rbgColor and is set at 2 seconds of solid led
void solidLED(int rgbColor){
strip.setPixelColor(0, rgbColor);//turns LED on green for duration of unlocking
strip.show();
softDelay(2000);
strip.setPixelColor(0, OFF);
strip.show();
}
void unlocking(){
lockstatus = "Unlocking...";
myTimerEvent();
Particle.publish("Unlock", "Door Unlocked");
rgbColor = PixelColorGreen;//sets color of led
numblinks = 25;//Sets the number of times to blink led, 15 blinks will result in 15 second delay
blinkrate = 500;
pinMode(DAC1, OUTPUT);//Turns pin on to output
digitalWrite(DAC1, LOW);
blinkLED(rgbColor,numblinks,blinkrate);//runs blink led while motor running
pinMode(DAC1, INPUT);//Turns pin off, otherwise pin always low
lockstatus = "Unlocked";
solidLED(rgbColor);//Ends with solid green led for 2 seconds
resetvars();
repeatactionlock = false;//clears true indicator from lock if lock was pressed more than once
}
void incorrectpass(){
lockstatus = "Try Again";
Particle.publish("Incorrect", "Incorrect Passcode Entered");
rgbColor = PixelColorRed;
numblinks = 4;
blinkrate = 500;
blinkLED(rgbColor,numblinks,blinkrate);
code = "";
resetvars();
}
void locking(){
lockstatus = "Locking...";
myTimerEvent();
Particle.publish("Lock", "Door Locked");
pinMode(D7, OUTPUT);//Turns pin on to output
digitalWrite(D7,LOW);
rgbColor = PixelColorGreen;
numblinks = 25;
blinkrate = 500; //calulate time of the blinking 25(blinks) * 50ms = 1250ms = 1.250s
blinkLED(rgbColor,numblinks,blinkrate);
pinMode(D7, INPUT);//Turns pin off, otherwise pin always low
lockstatus = "Locked";
solidLED(rgbColor);
resetvars();
repeatactionunlock = false;//clears true indicator from unlock if unlock was pressed more than once
}
//resets number of incorrect tries, allows the keypad to be used, reests code to blank
void resetvars(){
if (notcorrect == 0 || notcorrect == 3){
notcorrect = 0;
keypadlockout = 0;
code = "";
key = '$';
myTimerEvent();
casenumber = 0;
}
//doesnt let incorrect pass count reset to zero when there is 1 or 2 attempts at the password
else{
keypadlockout = 0;
code = "";
key = '$';
myTimerEvent();
casenumber = 0;
}
}
String PASSWORD = "1111";
void loop(){
Blynk.run();
timer.run();
key = keypad.getKey();
// builds code string with entered keys
if (keypadlockout == 0){
if((key == '1') || (key == '2') || (key == '3') || (key == '4') || (key == '5') || (key == '6') || (key == '7') || (key == '8') || (key == '9') || (key == '0')){
code = code + key;
strip.setPixelColor(0, PixelColorGreen);//turns LED on green for duration of unlocking
strip.show();
softDelay(100);
strip.setPixelColor(0, OFF);
strip.show();
}
}
if((key == '#') && (code == PASSWORD)){ //When # pressed, checks to see if the code string is equal to the password
if (repeatactionunlock == false){
casenumber = 1;
repeatactionunlock = true;
}
else if (repeatactionunlock == true){
rgbColor = PixelColorYellow;
numblinks = 4;
blinkrate = 500;
blinkLED(rgbColor,numblinks,blinkrate);
resetvars();
}
}
if((key == '#') && (code != PASSWORD)){ // If password incorrect the code resets to blank
casenumber = 2;
notcorrect++;//increments the notcorrect variable when user types in worng password
}
if(key == '*'){ //Updates lock status to locked
if (repeatactionlock == false){
casenumber = 3;
repeatactionlock = true;
}
else if (repeatactionlock == true){
rgbColor = PixelColorYellow;
numblinks = 4;
blinkrate = 500;
blinkLED(rgbColor,numblinks,blinkrate);
resetvars();
}
}
if (pinValue = 0){//For blynk button lock/unlock
//casenumber = 1;
}
if (pinValue = 1){//For blynk button lock/unlock
//casenumber = 2;
}
switch (casenumber)
{
case 1:{
unlocking();
break;
}
case 2:{
if (notcorrect == 3){// Looks to see if incorrect password has been entered 3 times
keypadlockout = 1; //locks out keypad input
lockstatus = "Keypad Locked for 10 s";
myTimerEvent();//updates blynk lock status
rgbColor = PixelColorRed;
numblinks = 10;
blinkrate = 500;
blinkLED(rgbColor,numblinks,blinkrate);
resetvars();
repeatactionunlock = false;
break;
}
if (notcorrect != 3){// whenever the number of attempts is below 3, program allows user to try again
incorrectpass();
repeatactionlock = false;
break;
}
}
case 3:{
locking();
break;
}
}
}