Skip to content

Instantly share code, notes, and snippets.

@JJTech0130
Created July 7, 2023 23:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save JJTech0130/38ea29836538f541a3195da6cdf6d7f6 to your computer and use it in GitHub Desktop.
Save JJTech0130/38ea29836538f541a3195da6cdf6d7f6 to your computer and use it in GitHub Desktop.
PICAXE program to use Snap Circuits keyboard (U26) with LED MC (U29)
; calling convention
symbol arg1 = b0
symbol arg2 = b1
symbol arg3 = b2
;symbol arg1w = w3
symbol shift_out_current_mask = b3
symbol shift_out_temp = b4
symbol main_last = b5
symbol main_last_mod = b6
symbol main_valid_cnt = b7
;symbol last_number = b20
;symbol main_last = b19
;symbol measure_pulse_out = w13
; pin definitions
symbol SHIFT_DATA = 1
symbol SHIFT_CLK = 0
symbol KEYBD_IN = 3
;symbol "C = %00000000
;main2:
; arg1 = "A"
; gosub display_letter
; arg1 = "B"
; gosub display_letter
; end
;main:
main:
gosub measure_pulse
if arg1 = 0 then
main_valid_cnt = 0
else
main_valid_cnt = main_valid_cnt + 1
endif
if main_valid_cnt < 20 then
goto main
endif
b27 = arg1
arg2 = 0
select case arg1
case 70 to 74
arg1 = "A"
case 66 to 69
arg1 = "A"
arg2 = 1
case 60 to 65
arg1 = "B"
endselect
b26 = arg1
b25 = arg2
if arg1 != main_last or arg2 != main_last_mod then
gosub display_letter
pause 400
;debug ; show it on the display before serial messes it up...
endif
main_last = arg1
main_last_mod = arg2
goto main
;arg1 = "C"
;setint 8,8
;gosub measure_pulse
;arg1 = b26 ; lower part of measure pulse out
;debug
;if arg1 = main_last then
; goto main
;endif
;main_last = main_last - 1
;if arg1 = main_last then
; goto main
;endif
;main_last = main_last + 2
;if arg1 = main_last then
; goto main
;endif
;main_last = arg1
;gosub display_number
goto main
;gosub display_hello
;goto main
end
measure_pulse:
pulsin KEYBD_IN, 1, w0 ; arg1 + arg2
return
; Segment layout:
; A
; F B
; G
; E C
; DH
;
; 0bHGFEDCBA
symbol DELAY = 500
display_hello:
; h
; 0111 0100
arg1 = 116
gosub shift_out
pause DELAY
; E
; 0111 1001
arg1 = 121
gosub shift_out
pause DELAY
; l
; 0011 0000
arg1 = 48
gosub shift_out
pause DELAY
; l
; 0011 0000
arg1 = 48
gosub shift_out
pause DELAY
; o
; 0101 1100
arg1 = 92
gosub shift_out
pause DELAY
; space
; 0000 0000
arg1 = 0
gosub shift_out
pause DELAY
return
display_number:
if arg1 > 99 then
arg1 = arg1 - 100
endif
arg2 = arg1
arg1 = arg2 / 10
gosub display_digit
arg1 = arg2 // 10
arg2 = 1
gosub display_digit
return
display_digit:
lookup arg1, (63,6,91,79,102,109,125,7,127,111,119,124,57,94,121,113,61,118,16,30,56,84,92,115,220,80,120,62,110), arg1
if arg2 = 1 then
arg1 = arg1 or %10000000 ; display decimal point
endif
gosub shift_out
return
display_letter:
select case arg1
case "A"
arg1 = %01110111
case "B"
arg1 = %01111100
case "C"
arg1 = %00111001
case "D"
arg1 = %01011110
case "E"
arg1 = %01111001
case "F"
arg1 = %01110001
case "G"
arg1 = %00111101
endselect
if arg2 = 1 then
arg1 = arg1 or %10000000 ; turn on decimal
endif
gosub shift_out
return
; the segments are daisy-chained right-to-left
; shift out what you want for the one on the left, then the one on the right to push it over
shift_out:
shift_out_current_mask = 1
shift_out_loop:
shift_out_temp = shift_out_current_mask and arg1 ; bitwise and
if shift_out_temp > 0 then
low SHIFT_DATA
else
high SHIFT_DATA
end if
high SHIFT_CLK
low SHIFT_CLK
shift_out_current_mask = shift_out_current_mask * 2
if shift_out_current_mask != 0 then shift_out_loop
return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment