Queens, New York
Offline
Edison Member
Karma: 31
Posts: 1726
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
|
 |
« Reply #15 on: January 23, 2013, 08:02:55 am » |
This has one too many values. int values[]={0, 58, 96, 145, 228, 335, 447, 598, 720, 809, 890, 941, 970}; Get rid of the first 0, to make it match, char mapping[]={'1','2','3','4','5','6','7','8','9','*','0','#'};
|
|
|
|
|
Logged
|
UNO, MEGA, NANO, 4x4 keypad, micro servos, RF transceivers, bluetooth, ultrasonic sensor, 20x4 I2C LCD, 3.2 TFT touch screen, L298N Dual motor driver, Voice Recognition 15W
"If your doing nothing, it does not mean your lazy, it just means your open for anything that suits you" - Unknown
|
|
|
|
UK Norfolk
Offline
Newbie
Karma: 0
Posts: 41
|
 |
« Reply #16 on: January 23, 2013, 03:59:56 pm » |
Hi HazardsMind. Thank you. Well done it compiles now and works. I have a few buttons on my keypad that give inconsistent readings though. Take button 4 for example it returns anything from 220-229 so I tried to adapt the "values" array to int values[12][3] = {{1, 50, 65}, // button 1 {2, 90, 110}, // button 2 {3, 137, 160}, // button 3 {4, 200, 245}, // button 4 {5, 300, 350}, // button 5 {6, 420, 470}, // button 6 {7, 500, 620}, // button 7 {8, 700, 745}, // button 8 {9, 780, 820}, // button 9 {10, 844, 900}, // button * {11, 930, 955}, // button 0 {12, 956, 999}}; // button # The trouble is it didn't work so I am back to square 1 on this but I have learned quite a bit over the last few days.I will have to try again on this. I have a 7 pin 4x3 keypad which is working fine on my project but, I just need to get this to work now,if nothing else just to show that it can be done. It is a wonder that more of you guys are not using a keypad like this to free up those digital pins. unless of course you are all using "Mega's" Regards Jeremy
|
|
|
|
|
Logged
|
There are times when electronics projects are like Women. Just when you think everything is fine the blow up in your face :-0
|
|
|
|
Central MN, USA
Offline
Faraday Member
Karma: 37
Posts: 6042
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
|
 |
« Reply #17 on: January 23, 2013, 05:00:12 pm » |
Jeremy,
Just use the center value between the max and min for each button in that sample code (sorry about the zero) and then look at the range of these values. There are 12 (effectively 13 values with the 0) so you are cutting the whole 1024 range into small sub-ranges. In the phi_interfaces library, there is a factor to decide the threshold of a match. Change that to maybe 20 so you will get more hits. The 2D array will not work with my library.
Open phi_interfaces.cpp and look for this line: if (diff<10)
Change 10 to 20. I should have defined a sensitivity=10 but didn't.
|
|
|
|
|
Logged
|
|
|
|
|
UK Norfolk
Offline
Newbie
Karma: 0
Posts: 41
|
 |
« Reply #18 on: January 23, 2013, 05:41:30 pm » |
Yes It works now. Thanks Liudr. Right now for the password part. I think I am getting there. It has taken me ages to get this idea working. I knew it could be done I just couldn't figure it out on my own. No problem about the "0" I should have spotted that myself. Have you made your own keypad yet? Jeremy
|
|
|
|
|
Logged
|
There are times when electronics projects are like Women. Just when you think everything is fine the blow up in your face :-0
|
|
|
|
Central MN, USA
Offline
Faraday Member
Karma: 37
Posts: 6042
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
|
 |
« Reply #19 on: January 23, 2013, 08:03:30 pm » |
I might be able to find you some code to enter password but if you want some simplicity, get my phi-panel serial lcd backpack with matrix keypad connection.
|
|
|
|
|
Logged
|
|
|
|
|
UK Norfolk
Offline
Newbie
Karma: 0
Posts: 41
|
 |
« Reply #20 on: January 23, 2013, 08:30:17 pm » |
Hi Liudr I would appreciate some code if you have some for the password. But as for the phi-panel serial lcd backpack. I would love one but I have no funds at the moment because I am on what you call welfare since my injury. I will make do with what I have in the way of hardware. my alarm when it is finally done will not have a display just some indicator led's. I will have to do something about my keypad though it is just 12 buttons soldered onto a piece of protoboard. But that may just confuse a Burglar. Regards Jeremy
|
|
|
|
|
Logged
|
There are times when electronics projects are like Women. Just when you think everything is fine the blow up in your face :-0
|
|
|
|
UK Norfolk
Offline
Newbie
Karma: 0
Posts: 41
|
 |
« Reply #21 on: January 24, 2013, 08:32:19 pm » |
Have you ever felt that you are in a real life void loop(){ try this; did it work y/n; n; try that; did it work y/n n; } Sorry but it is driving me nuts. Maybe I could learn to make cakes 
|
|
|
|
|
Logged
|
There are times when electronics projects are like Women. Just when you think everything is fine the blow up in your face :-0
|
|
|
|
Central MN, USA
Offline
Faraday Member
Karma: 37
Posts: 6042
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
|
 |
« Reply #22 on: January 24, 2013, 09:25:19 pm » |
I found some time today and wrote this code for you: #include <phi_interfaces.h>
#define buttons_per_column 6 // Each analog pin has five buttons with resistors. #define buttons_per_row 1 // There are two analog pins in use.
byte keypad_type=Analog_keypad; char mapping[]={'1','2','3','4','5','6'}; // This is an analog keypad. byte pins[]={0}; // The pin numbers are analog pin numbers. int values[]={14, 378, 563, 618, 656, 704}; //These numbers need to increase monotonically. phi_analog_keypads panel_keypad(mapping, pins, values, buttons_per_row, buttons_per_column); multiple_button_input* pad1=&panel_keypad;
char password[]="13531"; char buffer[20]; int pointer=0;
void setup() { Serial.begin(9600); Serial.println("Phi_interfaces library analog keypad test code: password"); digitalWrite(A0,HIGH); // DO this only if you are using phi-3 shield. }
void loop() { byte temp; Serial.println("Enter 5-digit password:"); while(1) { temp=panel_keypad.getKey(); // Use phi_keypads object to access the keypad // byte temp=pad1->getKey(); // Use the generic multiple_button_interface to access the same keypad if (temp!=NO_KEY) { Serial.write(temp); buffer[pointer++]=temp; if (pointer==5) { buffer[pointer]=0; pointer=0; if (!strcmp(buffer,password)) { Serial.println("Authenticated!"); } else { Serial.println("Unauthorized!"); } return; } } } }
It works on my phi-3 shield (experimental) so if you modify it to work on your keypad it should work too.
|
|
|
|
|
Logged
|
|
|
|
|
UK Norfolk
Offline
Newbie
Karma: 0
Posts: 41
|
 |
« Reply #23 on: January 25, 2013, 07:22:17 am » |
Hi Liudr. Thank you so much for the code. It works !!!! I cannot believe that after all this time I have a working analog keypad with a password function. It is coming together now and I am going to add a bit to it to get my PIR sensor working and buzzer and I will be there. Thanks again Jeremy
|
|
|
|
|
Logged
|
There are times when electronics projects are like Women. Just when you think everything is fine the blow up in your face :-0
|
|
|
|
UK Norfolk
Offline
Newbie
Karma: 0
Posts: 41
|
 |
« Reply #24 on: January 25, 2013, 08:33:27 pm » |
I have been at it all evening trying to get my PIR sensor to work. The only way I have found is to do away with the while statement. I had to turn off the Serial.println('Enter 5 digit password') line but I can not get the siren pin to go high, once switched on the sensor goes high before settling down. The sensor once tripped stays HIGH for five seconds before it goes LOW again. I need the siren to wait for that amount of time before going off or it will trip as soon as you power on the system. And I thought getting the keypad done was the hard bit. I think I may have bitten off more than I can chew here. I am not sure how to get the siren to wait but maybe the answer is using the millis function. I am not sure if that will influence the code I am using? Should i look at the blink without delay sketch or just use a switch case with a delay to wait for the sensor; I think I will sleep on it as it is 1:30 am Jeremy
|
|
|
|
|
Logged
|
There are times when electronics projects are like Women. Just when you think everything is fine the blow up in your face :-0
|
|
|
|
Central MN, USA
Offline
Faraday Member
Karma: 37
Posts: 6042
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
|
 |
« Reply #25 on: January 25, 2013, 09:00:47 pm » |
Hi Liudr. Thank you so much for the code. It works !!!! I cannot believe that after all this time I have a working analog keypad with a password function. It is coming together now and I am going to add a bit to it to get my PIR sensor working and buzzer and I will be there. Thanks again Jeremy
Jeremy, You are welcome. I will include this example in my next library release.
|
|
|
|
|
Logged
|
|
|
|
|
Central MN, USA
Offline
Faraday Member
Karma: 37
Posts: 6042
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
|
 |
« Reply #26 on: January 25, 2013, 09:03:13 pm » |
Yeah, the blink without delay example will help you multitask instead of just reading the keypad. Give it a try.
|
|
|
|
|
Logged
|
|
|
|
|
UK Norfolk
Offline
Newbie
Karma: 0
Posts: 41
|
 |
« Reply #27 on: January 28, 2013, 04:10:15 pm » |
Hi again. My brain aches and I still cannot get this to work. I have tried this way and that but nothing seem to work. The thing is that I know too little about programming to understand what I am doing wrong. This evening my computer crashed and I lost what I have been doing all day(I was an idiot and didn't save it) but then again it was not working anyway. If I use the millis function to time the amount of time the alarm sounds when it is triggered the keypad will not respond until the time millis function has completed. I had the siren sounding for 30 seconds and in that time the keypad will not function. Regards Jeremy
|
|
|
|
|
Logged
|
There are times when electronics projects are like Women. Just when you think everything is fine the blow up in your face :-0
|
|
|
|
Central MN, USA
Offline
Faraday Member
Karma: 37
Posts: 6042
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
|
 |
« Reply #28 on: January 28, 2013, 05:28:13 pm » |
Read about state machines. If you use delay, you won't be able to anything while delaying. If you want to use the keypad while the alarm is sounding for 30 seconds, you can't use delay, use state machine and timers instead. I didn't check on an arduino but it compiles. #include <phi_interfaces.h>
#define buttons_per_column 6 // Each analog pin has five buttons with resistors. #define buttons_per_row 1 // There are two analog pins in use.
byte keypad_type=Analog_keypad; char mapping[]={'1','2','3','4','5','6'}; // This is an analog keypad. byte pins[]={0}; // The pin numbers are analog pin numbers. int values[]={14, 378, 563, 618, 656, 704}; //These numbers need to increase monotonically. phi_analog_keypads panel_keypad(mapping, pins, values, buttons_per_row, buttons_per_column); multiple_button_input* pad1=&panel_keypad;
#define alarm_pin 10 enum States {get_password, alarm, cleared}; States system_state=get_password;
unsigned long alarm_starting, cleared_starting; char password[]="13531"; char buffer[20]; int pointer=0;
void setup() { }
void loop() { byte temp; switch (system_state) { case get_password: // do get password stuff temp=panel_keypad.getKey(); // Use phi_keypads object to access the keypad if (temp!=NO_KEY) { Serial.write(temp); buffer[pointer++]=temp; if (pointer==5) { buffer[pointer]=0; pointer=0; if (!strcmp(buffer,password)) { Serial.println("Authenticated!"); system_state=cleared; cleared_starting=millis(); // Open a door or something } else { Serial.println("Unauthorized!"); system_state=alarm; alarm_starting=millis(); tone(alarm_pin,550); } } } break; case alarm: if ((!panel_keypad.getKey())||(millis()-alarm_starting>=30000)) { system_state=get_password; noTone(alarm_pin); } break; case cleared: if ((!panel_keypad.getKey())||(millis()-cleared_starting>=30000)) { system_state=get_password; // Close the door or something. } break; } }
|
|
|
|
|
Logged
|
|
|
|
|
UK Norfolk
Offline
Newbie
Karma: 0
Posts: 41
|
 |
« Reply #29 on: January 28, 2013, 06:47:19 pm » |
Thank you liudr. I have had a quick look at your code. Before i even try to use it I will have a read about state machines. I will get back to you and let you know how I get on. regards Jeremy
|
|
|
|
|
Logged
|
There are times when electronics projects are like Women. Just when you think everything is fine the blow up in your face :-0
|
|
|
|
|