I am bogged down in this project
I am bogged down in this project
my code was basically from http://tronixstuff.com/tutorials > chapter 42. I have changed and added sections so that I can
1. Get a PIN for authority.
2. Get the message from the keypad.
3. Send the message wirelessly to another NRF24 / Arduino for display on a large 7 segment display.
4. Reset and wait for the next PIN etc.
I have all the sections working individually but cannot seem to go to the right section based on the results of the previous section.
In basic I would jump to a subroutine and go back to the main code for the next operation. In this sketch (LCDKeypad) I keep ending up in the wrong place in the code.
This is probably just my lack of understanding of C++.I have looked over many samples but cannot find code close enough to help me.could you please look over the sketch
and provide guidance. your previous help is very much appreciated.
//keypad/LCD combo // http://tronixstuff.com/tutorials > chapter 42 #include <Wire.h> #include <Keypad.h> #include<LiquidCrystal.h> //Char Kid(); // need string here LiquidCrystal lcd(27, 26, 25, 24, 23, 22); // Create the Keypad const byte ROWS = 4; // Four rows const byte COLS = 3; // Three columns // Define the Keymap char keys[ROWS][COLS] = { {'1', '2', '3'}, {'4', '5', '6'}, {'7', '8', '9'}, {'*', '0', '#'} }; //define Arduino pins & rows byte rowPins[ROWS] = {2, 3, 4, 5}; byte colPins[COLS] = {6, 7, 8}; //KeyMap Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS ); //////// AUTHORIZATION CODE /////// // Change Here if new one is desired // char PIN[4] = {'4', '3', '1','6'}; // our secret (!) number char attempt[4] = {'0', '0', '0','0'}; // used for comparison int z = 0; //************* SETUP ******************************* void setup() { Serial.begin(9600); lcd.begin(16, 2); delay(100); lcd.clear(); lcd.print(" Enter PIN..."); lcd.setCursor(6, 1); lcd.cursor(); lcd.blink(); } //*********** PIN OK ********************* void correctPIN() // do this if correct PIN entered { int(j); for ( j = 0; j < 4 ; j++ ) lcd.clear(); lcd.print(" Enter Kid #"); Serial.print("I got here"); /////////test/////// /* char key = keypad.getKey(); //delay(100); if (key != NO_KEY) { lcd.print(key); attempt[j] = key; j++; Serial.print("I got here"); /////////test/////// char(Kid) = key; lcd.print(Kid); } switch (key) { case '*': z = 0; break; case '#': z = 0; //lcd.clear(); //lcd.print(" Enter PIN..."); lcd.setCursor(6, 1); } */ } //************ incorrect pin entered ******************* void incorrectPIN() // do this if incorrect PIN entered { lcd.clear(); delay(100); lcd.print(" * Try Again *"); delay(2000); lcd.clear(); lcd.print(" Enter PIN..."); lcd.setCursor(6, 1); } //************** CHECK PIN ******************************** void checkPIN() { int correct = 0; int i; for ( i = 0; i < 4 ; i++ ) { Serial.print(correct); if (attempt[i] == PIN[i]) { correct++; // Serial.print(PIN); //Serial.print(i); // Serial.print(i); if (correct == 3); correctPIN(); } else incorrectPIN(); } for (int zz = 0; zz < 3; zz++) { attempt[zz] = '0'; } } //************** READ KEPAD ******************************** void readpad() { char key = keypad.getKey(); delay(100); if (key != NO_KEY) { lcd.print(key); attempt[z] = key; z++; } switch (key) { case '*': z = 0; break; case '#': z = 0; // delay(100); // for extra debounce // lcd.clear(); checkPIN(); break; } } //*************** LOOP ********** void loop() { readpad();
Bob:
I just received the 8574 chips i ordered and everything works great.
Thanks again for the sketch ,the library and you help.
Norm