I am using a reset function in my code but for some reason it’s not resetting my Arduino.
I tested the function with other code and it worked but in this one it didn’t. I tried calling the function in different spot in the code but no results.
This project is using an Arduino Uno, a keypad, shift registers, LEDs, resistors and wires.
I am working on breadboard to test before I put the project together.
Basically the project is like this: when the person pushes a key a message start scrolling if the PIR detected motion if not the Arduino should reset itself through the reset function (which I tested and worked) and the Arduino waits to detect another person or wait for another key to be pushed and display another message (of course if motion is detected)
I hope someone looks at my code and help me find out why the resetFunc() is not working.
Note: I only have one case in the switch. I am trying first to get work with one. The rest should be the same.
Currently, when I push the Key "1" from the keypad nothing happen until i wave my hand near the PIR which is what I want but it keeps scrolling for ever even if I am not near the PIR.
Thank you.
#include <Keypad.h>
const byte ROWS = 2;
const byte COLS = 2;
char keys[ROWS][COLS] =
{
{
'1','3' }
,
{
'7','9' }
,
};
byte rowPins [ROWS] = {
5,6};
byte colPins [COLS] = {
7,8};
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
int pirPin = 9;
int dataPin1 = 13; //Name Pin. Define which pins will be used for the Shift Register control
int dataPin2 = 10; //Off Pin
int dataPin3 = 11; //CVN Pin
int dataPin4 = 12; //Vacation Pin
int dataPin5 = 2; //Here Pin
int latchPin = 3;
int clockPin = 4;
int val = 0;
int pirState = LOW;
int PirState = PirFun();
int seq[14] = {
1,2,4,8,16,32,64,128,64,32,16,8,4,2}; //The byte sequence
void setup()
{
Serial.begin (9600);
pinMode(dataPin1, OUTPUT);
pinMode(dataPin2, OUTPUT);
pinMode(dataPin3, OUTPUT);
pinMode(dataPin4, OUTPUT);
pinMode(dataPin5, OUTPUT);
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(pirPin, INPUT);
}
void handleKeypress (const char key)
{
Serial.println (key);
}
void(* resetFunc)(void)=0;
boolean PirFun(){
val = digitalRead(pirPin);
}
void loop()
{
for (int n = 0; n < 14; n++)
{
digitalWrite(latchPin, LOW); //Pull latch LOW to start sending data
shiftOut(dataPin1, clockPin, MSBFIRST, seq[n]); //Send the data
digitalWrite(latchPin, HIGH); //Pull latch HIGH to stop sending data
delay(30);
}
byte key = kpd.getKey();
if (key)
handleKeypress (key);
switch (key) {
case '1':
while(PirState == HIGH){
for (int n = 0; n < 14; n++)
{
digitalWrite(latchPin, LOW); //Pull latch LOW to start sending data
shiftOut(dataPin1, clockPin, MSBFIRST, seq[n]); //Send the data
digitalWrite(latchPin, HIGH); //Pull latch HIGH to stop sending data
delay(10);
}
for (int n = 0; n < 14; n++)
{
digitalWrite(latchPin, LOW); //Pull latch LOW to start sending data
shiftOut(dataPin2, clockPin, MSBFIRST, seq[n]); //Send the data
digitalWrite(latchPin, HIGH); //Pull latch HIGH to stop sending data
delay(10);
}
}
break;
}
if(PirState == LOW){
resetFunc();
}
}