Advertisement
Jan-Langevad

ESP32104.txt

May 24th, 2024 (edited)
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.37 KB | None | 0 0
  1. \ ESP32104.txt
  2. \ Challenge "10 keys, 4 resistors, 4 ports" Jan Langevad 7th. June 2024
  3. \ IDEA: Use a TASK to constantly read ADC values, and set status actual for keys [ ]
  4. \ Ports have to be pulled to LOW with a e.g. 500K+ resistor (?) - breaking the challenge limitations!
  5. \ BUT using 4 ports with ADC, and a few more resistors, can control e.g. 20 keys/contacts! Like here:
  6.  
  7. \ 3,3V-----[1K]--V--[1K]--V--[1K]--V--[1K]--V--[1K]--V--[1K]-------GND giving 5 voltage (analog) values
  8. \ | | | | |
  9. \ | | | | |
  10. \ Port1----------7--------8--------9-------TIM------IN---[500K+]----GND
  11. \ | | | | |
  12. \ Port2----------4--------5--------6-------CNT------OUT--[500K+]----GND
  13. \ | | | | |
  14. \ Port3----------1--------2--------3--------^-------DIS--[500K+]----GND
  15. \ | | | | |
  16. \ Port4---------DEL-------0-------REG------SFT------INS--[500K+]----GND
  17.  
  18.  
  19. \ Use named value to check ADC value in acceptable ranges - contact noise elimination
  20. 0 value V1
  21. 0 value V2
  22. 0 value V3
  23. 0 value V4
  24. 0 value V5
  25.  
  26. \ value ADC input LIMITS control
  27. 0 value lowest
  28. 0 value highest
  29.  
  30. \ Assign input pins for use as ADC inputs (=default PIN mode @ ESP32 - and digital Input)
  31. 13 value P1PIN
  32. 12 value P2PIN
  33. 14 value P3PIN
  34. 27 value P4PIN
  35.  
  36. : LEDon HIGH LED pin ;
  37. : LEDoff LOW LED pin ;
  38.  
  39. : P1 \ Test the variable level on Port1 PIN
  40. P1PIN ADC to V1
  41. \ P1PIN ADC to V2
  42. \ P1PIN ADC to V3
  43. \ P1PIN ADC to V4
  44. \ P1PIN ADC to V5
  45. ;
  46.  
  47. : P2 \ Test the variable level on Port2 PIN
  48. P2PIN ADC to V1
  49. \ P2PIN ADC to V2
  50. \ P2PIN ADC to V3
  51. \ P2PIN ADC to V4
  52. \ P2PIN ADC to V5
  53. ;
  54.  
  55. : P3 \ Test the variable level on Port3 PIN
  56. P3PIN ADC to V1
  57. \ P3PIN ADC to V2
  58. \ P3PIN ADC to V3
  59. \ P3PIN ADC to V4
  60. \ P3PIN ADC to V5
  61. ;
  62.  
  63. : P4 \ Test the variable level on Port4 PIN
  64. P4PIN ADC to V1
  65. \ P4PIN ADC to V2
  66. \ P4PIN ADC to V3
  67. \ P4PIN ADC to V4
  68. \ P4PIN ADC to V5
  69. ;
  70.  
  71. \ Seems to work OK with just one reading og Voltage level,on ADC port, when externalpull down is used.
  72.  
  73.  
  74. : Rangetest \ used to determine highest and lowest ADC value in your HW setup.
  75. P1 cr v1 v2 v3 v4 v5 . . . . . cr
  76. ;
  77.  
  78. : FORMER-Range ( lowest highest --- flg) \ check all readings are within a defined range
  79.  
  80. is highest
  81. is lowest
  82.  
  83. v1 lowest >
  84. v2 lowest >
  85. v3 lowest >
  86. v4 lowest >
  87. v5 lowest >
  88.  
  89. v1 highest <
  90. v2 highest <
  91. v3 highest <
  92. v4 highest <
  93. v5 highest <
  94.  
  95. and and and and
  96. and and and and
  97. and \ All tests OK?
  98. ;
  99.  
  100. \ This more simple version seems to work just fine:
  101. : Range ( lowest highest --- flg) \ check readings are within a defined range
  102.  
  103. is highest
  104. is lowest
  105.  
  106. v1 lowest >
  107. v1 highest <
  108. and \ Tests OK?
  109. ;
  110.  
  111. \ Range settings are wider than actual measured values - not critical:
  112. : Column1? 3100 3400 Range ;
  113. : Column2? 2400 2700 Range ;
  114. : Column3? 1700 2100 Range ;
  115. : Column4? 1000 1400 Range ;
  116. : Column5? 300 700 Range ;
  117.  
  118. : ShowAndPause LEDoff 200 ms LEDon ;
  119.  
  120. : Test BEGIN P1PIN ADC \ --- ADCvalue
  121. if P1 \ not zero Go check ADC range:
  122. Column1? if ." 7" ShowAndPause then
  123. Column2? if ." 8" ShowAndPause then
  124. Column3? if ." 9" ShowAndPause then
  125. Column4? if ." TIM " ShowAndPause then
  126. Column5? if ." IN " ShowAndPause then
  127. then
  128.  
  129. P2PIN ADC \ --- ADCvalue
  130. if P2 \ not zero Go check ADC range:
  131. Column1? if ." 4" ShowAndPause then
  132. Column2? if ." 5" ShowAndPause then
  133. Column3? if ." 6" ShowAndPause then
  134. Column4? if ." CNT " ShowAndPause then
  135. Column5? if ." OUT " ShowAndPause then
  136. then
  137.  
  138. P3PIN ADC \ --- ADCvalue
  139. if P3 \ not zero Go check ADC range:
  140. Column1? if ." 1" ShowAndPause then
  141. Column2? if ." 2" ShowAndPause then
  142. Column3? if ." 3" ShowAndPause then
  143. Column4? if ." ^ " ShowAndPause then
  144. Column5? if ." DIS " ShowAndPause then
  145. then
  146.  
  147. P4PIN ADC \ --- ADCvalue
  148. if P4 \ not zero Go check ADC range:
  149. Column1? if ." DEL " ShowAndPause then
  150. Column2? if ." 0 " ShowAndPause then
  151. Column3? if ." REG " ShowAndPause then
  152. Column4? if ." SFT " ShowAndPause then
  153. Column5? if ." INS " ShowAndPause then
  154. then
  155.  
  156. 100 ms \ <****************
  157. Key?
  158. UNTIL
  159. ;
  160.  
  161. \ EOF
  162.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement