Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- \ ESP32104.txt
- \ Challenge "10 keys, 4 resistors, 4 ports" Jan Langevad 7th. June 2024
- \ IDEA: Use a TASK to constantly read ADC values, and set status actual for keys [ ]
- \ Ports have to be pulled to LOW with a e.g. 500K+ resistor (?) - breaking the challenge limitations!
- \ BUT using 4 ports with ADC, and a few more resistors, can control e.g. 20 keys/contacts! Like here:
- \ 3,3V-----[1K]--V--[1K]--V--[1K]--V--[1K]--V--[1K]--V--[1K]-------GND giving 5 voltage (analog) values
- \ | | | | |
- \ | | | | |
- \ Port1----------7--------8--------9-------TIM------IN---[500K+]----GND
- \ | | | | |
- \ Port2----------4--------5--------6-------CNT------OUT--[500K+]----GND
- \ | | | | |
- \ Port3----------1--------2--------3--------^-------DIS--[500K+]----GND
- \ | | | | |
- \ Port4---------DEL-------0-------REG------SFT------INS--[500K+]----GND
- \ Use named value to check ADC value in acceptable ranges - contact noise elimination
- 0 value V1
- 0 value V2
- 0 value V3
- 0 value V4
- 0 value V5
- \ value ADC input LIMITS control
- 0 value lowest
- 0 value highest
- \ Assign input pins for use as ADC inputs (=default PIN mode @ ESP32 - and digital Input)
- 13 value P1PIN
- 12 value P2PIN
- 14 value P3PIN
- 27 value P4PIN
- : LEDon HIGH LED pin ;
- : LEDoff LOW LED pin ;
- : P1 \ Test the variable level on Port1 PIN
- P1PIN ADC to V1
- \ P1PIN ADC to V2
- \ P1PIN ADC to V3
- \ P1PIN ADC to V4
- \ P1PIN ADC to V5
- ;
- : P2 \ Test the variable level on Port2 PIN
- P2PIN ADC to V1
- \ P2PIN ADC to V2
- \ P2PIN ADC to V3
- \ P2PIN ADC to V4
- \ P2PIN ADC to V5
- ;
- : P3 \ Test the variable level on Port3 PIN
- P3PIN ADC to V1
- \ P3PIN ADC to V2
- \ P3PIN ADC to V3
- \ P3PIN ADC to V4
- \ P3PIN ADC to V5
- ;
- : P4 \ Test the variable level on Port4 PIN
- P4PIN ADC to V1
- \ P4PIN ADC to V2
- \ P4PIN ADC to V3
- \ P4PIN ADC to V4
- \ P4PIN ADC to V5
- ;
- \ Seems to work OK with just one reading og Voltage level,on ADC port, when externalpull down is used.
- : Rangetest \ used to determine highest and lowest ADC value in your HW setup.
- P1 cr v1 v2 v3 v4 v5 . . . . . cr
- ;
- : FORMER-Range ( lowest highest --- flg) \ check all readings are within a defined range
- is highest
- is lowest
- v1 lowest >
- v2 lowest >
- v3 lowest >
- v4 lowest >
- v5 lowest >
- v1 highest <
- v2 highest <
- v3 highest <
- v4 highest <
- v5 highest <
- and and and and
- and and and and
- and \ All tests OK?
- ;
- \ This more simple version seems to work just fine:
- : Range ( lowest highest --- flg) \ check readings are within a defined range
- is highest
- is lowest
- v1 lowest >
- v1 highest <
- and \ Tests OK?
- ;
- \ Range settings are wider than actual measured values - not critical:
- : Column1? 3100 3400 Range ;
- : Column2? 2400 2700 Range ;
- : Column3? 1700 2100 Range ;
- : Column4? 1000 1400 Range ;
- : Column5? 300 700 Range ;
- : ShowAndPause LEDoff 200 ms LEDon ;
- : Test BEGIN P1PIN ADC \ --- ADCvalue
- if P1 \ not zero Go check ADC range:
- Column1? if ." 7" ShowAndPause then
- Column2? if ." 8" ShowAndPause then
- Column3? if ." 9" ShowAndPause then
- Column4? if ." TIM " ShowAndPause then
- Column5? if ." IN " ShowAndPause then
- then
- P2PIN ADC \ --- ADCvalue
- if P2 \ not zero Go check ADC range:
- Column1? if ." 4" ShowAndPause then
- Column2? if ." 5" ShowAndPause then
- Column3? if ." 6" ShowAndPause then
- Column4? if ." CNT " ShowAndPause then
- Column5? if ." OUT " ShowAndPause then
- then
- P3PIN ADC \ --- ADCvalue
- if P3 \ not zero Go check ADC range:
- Column1? if ." 1" ShowAndPause then
- Column2? if ." 2" ShowAndPause then
- Column3? if ." 3" ShowAndPause then
- Column4? if ." ^ " ShowAndPause then
- Column5? if ." DIS " ShowAndPause then
- then
- P4PIN ADC \ --- ADCvalue
- if P4 \ not zero Go check ADC range:
- Column1? if ." DEL " ShowAndPause then
- Column2? if ." 0 " ShowAndPause then
- Column3? if ." REG " ShowAndPause then
- Column4? if ." SFT " ShowAndPause then
- Column5? if ." INS " ShowAndPause then
- then
- 100 ms \ <****************
- Key?
- UNTIL
- ;
- \ EOF
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement