Skip to content

Instantly share code, notes, and snippets.

@stianeikeland
Created March 21, 2014 18:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stianeikeland/9692852 to your computer and use it in GitHub Desktop.
Save stianeikeland/9692852 to your computer and use it in GitHub Desktop.
;; Anything you type in here will be executed
;; immediately with the results shown on the
;; right.
(import [com.pi4j.wiringpi Spi])
(def reg {:no-op (byte 0x0)
:row-1 (byte 0x1)
:row-2 (byte 0x2)
:row-3 (byte 0x3)
:row-4 (byte 0x4)
:row-5 (byte 0x5)
:row-6 (byte 0x6)
:row-7 (byte 0x7)
:row-8 (byte 0x8)
:decode-mode (byte 0x9)
:intensity (byte 0xa)
:scan-limit (byte 0xb)
:shutdown (byte 0xc)
:display-test (byte 0xf)})
(def rows [(byte 0x1) (byte 0x2) (byte 0x3) (byte 0x4) (byte 0x5) (byte 0x6) (byte 0x7) (byte 0x8)])
(defn send! [a b]
(Spi/wiringPiSPIDataRW Spi/CHANNEL_0 (byte-array [(byte a) (byte b)]) 2))
(defn sendboth! [a b c]
(Spi/wiringPiSPIDataRW Spi/CHANNEL_0 (byte-array [(byte a) (byte b) (byte a) (byte c)]) 4))
;(Spi/wiringPiSPISetup Spi/CHANNEL_0 10000000)
(send! (reg :scan-limit) (byte 0x7))
(send! (reg :decode-mode) (byte 0x0))
(send! (reg :shutdown) (byte 0x1))
(send! (reg :display-test) (byte 0x0))
; Clear all rows
(map #(send! %1 %2) rows (take 8 (repeat (byte 0x0))))
(Spi/wiringPiSPIDataRW Spi/CHANNEL_0 (byte-array [(byte 1) (byte -1) (byte 1) (byte 8)]) 4)
(dotimes [n 127]
(Thread/sleep 100)
(dotimes [x 8]
(Spi/wiringPiSPIDataRW Spi/CHANNEL_0 (byte-array [(byte (inc x)) (byte (- 127 n)) (byte (inc x)) (byte n)]) 4)))
(send! (byte 1) (byte 32))
(send! (byte 2) (byte 80))
(send! (byte 3) (byte 16))
(send! (byte 4) (byte 8))
(send! (byte 5) (byte 24))
(send! (byte 6) (byte 52))
(send! (byte 7) (byte 101))
(send! (byte 8) (byte -62))
(sendboth! (byte 1) (byte 32) (byte -33))
(sendboth! (byte 2) (byte 80) (byte -81))
(sendboth! (byte 3) (byte 16) (byte -17))
(sendboth! (byte 4) (byte 8) (byte -9))
(sendboth! (byte 5) (byte 24) (byte -25))
(sendboth! (byte 6) (byte 52) (byte -53))
(sendboth! (byte 7) (byte 101) (byte -102))
(sendboth! (byte 8) (byte -62) (byte 61))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment