Tally counter, key click, beep

Popular in previous forums place your programming snippets here
Post Reply
Daren
Posts: 70
Joined: Tue Jan 03, 2023 10:03 pm

Tally counter, key click, beep

Post by Daren »

Here are a few snippets that I uploaded to the previous forum.

Use for incremental/decremental counting using arrow up/down keys, can start from a specified number and has reset to zero by pressing "Z", useful for music beat counting or keeping track of people entering/leaving etc.

Code: Select all

TALY:
LOCAL A%,KEY%
KSTAT 3
PRINT "Start From?"
INPUT A%
CLS
DO::
PRINT 
PRINT "      [";CHR$(169);"]";"[";CHR$(170);"]",A%
PRINT
PRINT"   [Z]ero  [Q]uit"

KEY%=GET
CLS
IF KEY%=3
A%=A%+1

GOTO DO::
ELSEIF KEY%=4
A%=A%-1

GOTO DO::
ELSEIF KEY%=%.
A%=0

GOTO DO::
ELSEIF KEY%=%6
ELSE GOTO DO::
ENDIF
Sets the key click sound, 0 is silent, 1 is default, 2 is a bit louder without being annoying, anything beyond about 30 might give a bit of input lag.

Code: Select all

KCLK:
LOCAL S%
PRINT
PRINT " Current Setting",PEEKB(8384)
GET
CLS
PRINT
PRINT "   New Setting"
AT 17,2: INPUT S%
POKEB 8384,S%

Beeps the piezo for the specified duration and frequency.

Code: Select all

BEEP:
LOCAL D%,F%,KEY%
START::
KSTAT 3
CLS
POKEB 8384,2
PRINT "Enter Duration"
INPUT D%
FREQ::
PRINT "Enter Frequency"
INPUT F%
POKEB 8384,0
REPLAY::
CLS
BEEP D%,F%
PRINT "Duration",D%
PRINT "Frequency",F%
PRINT "[P]lay [Q]uit"
PRINT "[A]new [F]req"
ASK::
KSTAT 1
KEY%=GET
IF KEY%=%A
GOTO START::
ELSEIF KEY%=%P
GOTO REPLAY::
ELSEIF KEY%=%F
CLS
GOTO FREQ::
ELSEIF KEY%=%Q
POKEB 8384,2
ELSE GOTO ASK::
RETURN
ENDIF
Post Reply