Hi
I am trying to build a keyless entry using a keypad/resistors. Can't find any examples with Annex. Can anyone translate this C++ to Annex for me?
Thanks
Zim
Keypad help please
Keypad help please
You do not have the required permissions to view the files attached to this post.
- cicciocb
- Site Admin
- Posts: 2095
- Joined: Mon Feb 03, 2020 1:15 pm
- Location: Toulouse
- Has thanked: 450 times
- Been thanked: 1385 times
- Contact:
Re: Keypad help please
this should be a "raw" conversion of the code
However, you must consider the resolution of the ADC that is 12 bits vs 10 bits of the Arduino so the table must be changed (with a raw approximation multiplied by 4).
Anyway, I don't think is a good idea as the ADC converter of the ESP32 is not very stable and the resistor values could change with the temperature so I suggest to use a classic scan technique.
You can find a good inspiration from a demo project I did some time ago on WOKWI
https://wokwi.com/projects/343447488070419027
Code: [Local Link Removed for Guests]
dim thresholds(16) = 2, 77, 144, 202, 244, 290, 331, 368, 394, 424, 452, 488, 496, 518, 556
dim keypad$(16) = "1", "2", "3", "4", "5", "6", "B", "7", "8", "9", "C", "*", "0", "#", "D"
adc_pin = 39
do
value = adc(adc_pin )
for i = 0 to 15
if abs(value - thresholds(i)) < 5 then
print keypad$(i)
while adc(adc_pin) < 1000
pause 100
wend
end if
next i
loop
Anyway, I don't think is a good idea as the ADC converter of the ESP32 is not very stable and the resistor values could change with the temperature so I suggest to use a classic scan technique.
You can find a good inspiration from a demo project I did some time ago on WOKWI
https://wokwi.com/projects/343447488070419027
You do not have the required permissions to view the files attached to this post.
-
- Posts: 146
- Joined: Mon Feb 08, 2021 10:10 pm
- Location: Scotland
- Has thanked: 48 times
- Been thanked: 56 times
Re: Keypad help please
Also, the arduino design used 5 volts so with 3.3 volts it is likely all the thresholds will need changing and the "width" of each will be only 2/3 of the original.
Re: Keypad help please
Thanks a ton for the interpretation and the suggestions! Exactly what I needed![Local Link Removed for Guests] wrote: [Local Link Removed for Guests]Wed May 01, 2024 8:11 am this should be a "raw" conversion of the codeHowever, you must consider the resolution of the ADC that is 12 bits vs 10 bits of the Arduino so the table must be changed (with a raw approximation multiplied by 4).Code: [Local Link Removed for Guests]
dim thresholds(16) = 2, 77, 144, 202, 244, 290, 331, 368, 394, 424, 452, 488, 496, 518, 556 dim keypad$(16) = "1", "2", "3", "4", "5", "6", "B", "7", "8", "9", "C", "*", "0", "#", "D" adc_pin = 39 do value = adc(adc_pin ) for i = 0 to 15 if abs(value - thresholds(i)) < 5 then print keypad$(i) while adc(adc_pin) < 1000 pause 100 wend end if next i loop
Anyway, I don't think is a good idea as the ADC converter of the ESP32 is not very stable and the resistor values could change with the temperature so I suggest to use a classic scan technique.
You can find a good inspiration from a demo project I did some time ago on WOKWI
Zim
Re: Keypad help please
cicciocb
I hate to be a pest....could you modify this for a 4x3 keypad with one less column?
I changed "dim cols(4) = 35, 34, 39, 36" to "dim cols(3) = 35, 34, 39"
dim sym$(16).... to dim sym$(12)......
seems to work except the last column
it gives a error on line 59
any ideas?
Thanks
Zim
I hate to be a pest....could you modify this for a 4x3 keypad with one less column?
I changed "dim cols(4) = 35, 34, 39, 36" to "dim cols(3) = 35, 34, 39"
dim sym$(16).... to dim sym$(12)......
seems to work except the last column
it gives a error on line 59
any ideas?
Thanks
Zim
Code: [Local Link Removed for Guests]
' demo use of the keypad scan
' a complete help of Annex32 can be found here
' https://cicciocb.com/annex32help/V1.442/
dim rows(4) = 26, 25, 33, 32
dim cols(3) = 35, 34, 39
'dim sym$(16) = "1", "2", "3", "A", "4", "5", "6", "B", "7", "8", "9", "C", "*", "0", "#", "D"
dim sym$(12) = "1", "2", "3", "4", "5", "6", "7", "8", "9", "*", "0", "#" 'added this???????????????
' set the pins as input and output
for z = 0 to 3
pin.mode rows(z), output
pin(rows(z)) = 0
next z
for z = 0 to 2 'added this ??????????????????
pin.mode cols(y), input, pulldown 'added this ?????????????????
next y
'maxscroll.setup 8, 21
'maxscroll.print "Press Keys"
'maxscroll.show 63, 5
k$ = ""
Kp$ = ""
line$ = space$(16)
do
scan k$
if (k$ <> kp$) and (k$ <> "") then
print k$
line$ = right$(line$ + k$, 10)
' maxscroll.text line$
'maxscroll.show 64, 5
end if
kp$ = k$
'pause 100
loop
sub scan(key$)
local r, c, l, code
code = -1
for r = 0 to 3
pin(rows(r)) = 1
for c = 0 to 3
l = pin(cols(c))
if (l=1) then
code = r*4 + c
exit for
end if
next c
pin(rows(r)) = 0
if (code <> -1) then exit for
next r
if (code <> -1) then key$ = sym$(code) else key$ = ""
end sub
- cicciocb
- Site Admin
- Posts: 2095
- Joined: Mon Feb 03, 2020 1:15 pm
- Location: Toulouse
- Has thanked: 450 times
- Been thanked: 1385 times
- Contact:
Re: Keypad help please
You must change the line 49
from
to
from
Code: [Local Link Removed for Guests]
for c = 0 to 3
Code: [Local Link Removed for Guests]
for c = 0 to 2