phil99
 Guru
 Joined: 11/02/2018 Location: AustraliaPosts: 3321 |
| Posted: 05:38am 04 Dec 2022 |
|
|
|
Using Peter's insight and adding provision for a second button (top one in the above diagram) to delete the last letter. It should work as you intend with your current wiring. The extra lines should not matter.
' *************************************** ' Text input with poti (TimD and phil99) ' ADC0, 1k-10k-1k gives (measured): ' 0.2790...3.0080 V over poti ' Switch down on lower R1k: 0.0130 V ' Poti works ok ==> shows A...Z ' Newname shows ??? instead '****************************************
SetPin GP26, AIN 'ADC0 at pin31
' !! inverted colors because of "false" driver for LCD!! Take RGB values Const black_= RGB(255,255,255) 'black inv. Const green_= RGB(255,127,255) 'green inv. Const yellow_= RGB(0,0,255) 'yellow inv.
Dim letter As string length 1 'letter for name Dim newname As string
newname = ""
CLS black_ 'display black, iRGB of (0,0,0) Box 0,0,320,240,1, yellow_ Font 2, 1
Again: Do NewLetter = 0 : finished = 0 mvolt=Int(1000*Pin(31)) 'millivolt If (mvolt > 220) And (mvolt < 3100) Then 'Read letter if no buttons pressed diff=3008-279 'measured min/max du=diff/25 '26-1 between u=Int(mvolt/du)-1 'first # should be 1 letter=Chr$(u+64) 'A is chr$(65) Text 4, 100, "Letter is: " + letter,,2,, yellow_, black_ 'is ok, A...Z Pause 100 EndIf
If mvolt < 220 Then 'If lower button pressed add current letter Timer = 0 Do mvolt=Int(1000*Pin(31)) 'millivolt If Timer > 1500 Then Finished = 1 Loop While (mvolt < 220) And (finished = 0) 'wait for button release NewLetter = 1 Print newname EndIf
If mvolt > 3100 Then 'If upper button pressed remove last letter Timer = 0 Do mvolt=Int(1000*Pin(31)) 'millivolt If Timer > 1500 Then Finished = 1 Loop While (mvolt > 3100) And (finished = 0) 'wait for button release If Len(newname) > 0 Then newname = Left$(newname, Len(newname)-1) Text 4, 100, "Letter is: " + letter,,2,, yellow_, black_ 'is ok, A...Z Print newname NewLetter = 1 EndIf
Loop Until (NewLetter =1) Or (Finished =1) 'leave the loop
Take: newname = newname + letter '??? only, letter lost Text 4, 16, "New name is: " + " ",,2,, yellow_, black_ Text 4, 16, "New name is: " + newname,,2,, yellow_, black_
If Finished = 0 Then GoTo Again Print newname Text 4, 200, "Saved name is: " + newname,,2,, yellow_, black_
'How to save the name? >=== long press End
edit got something wrong in the delete letter loop but otherwise seems ok. Edited 2022-12-04 17:26 by phil99 |