; ; Adafruit CLUE TFT colour display plotting demo - see http://www.ulisp.com/show?2ZD1 ; ; Pins used for CLUE display (defvar dc 32) (defvar cs 31) ; Display commands (defvar CASET #x2A) (defvar RASET #x2B) (defvar RAMWR #x2C) ; Display offsets and dimensions (defvar yoff 0) (defvar xoff 80) (defvar xsize 240) (defvar ysize 240) (defvar invert 1) (defvar rot 6) ; Convert red, green, blue components 0 to 255 to a 16-bit 565 RGB value (defun rgb (r g b) (logior (ash (logand r #xf8) 8) (ash (logand g #xfc) 3) (ash b -3))) ; Write a command with optional data bytes (defun cmd (c &rest data) (with-spi (str cs 4000 1 0 1) (digitalwrite dc 0) (write-byte c str) (digitalwrite dc 1) (dolist (d data) (write-byte d str)))) ; Initialize the display (defun init () (pinmode dc t) (cmd #x01) ; Software reset (delay 150) ; delay 150 ms (cmd #x11) ; Out of sleep mode (delay 10) ; delay 10 ms (cmd #x3A #x55) ; Set color mode - 16-bit color (cmd (+ #x20 invert)) ; Invert? (cmd #x36 (ash rot 5)); Set orientation (cmd #x29) ; Display on (delay 10)) ; Plot point at x,y (defun point (x y colour) (let ((v (+ yoff y)) (h (+ xoff x))) (cmd CASET (ash v -8) v (ash v -8) v) (cmd RASET (ash h -8) h (ash h -8) h) (cmd RAMWR (ash colour -8) colour))) (defun plot () (dotimes (xx 240) (let ((x (- xx 120))) (dotimes (yy 240) (let* ((y (- yy 120)) (f (truncate (+ (* x (+ x y)) (* y y)) 8))) (point xx yy (rgb (+ f 160) f (+ f 80))))))))