Here’s a simple application showing how to read a MCP9808 temperature sensor and change the colour of an RGB LED from blue to red as the ambient temperature rises from 20°C to 35°C:
Here’s the full program in uLisp:
(defvar blu 10)
(defvar red 11)
(defun led ()
(loop
(with-i2c (str 31)
(write-byte 5 str)
(restart-i2c str 2)
(let* ((hi (read-byte str))
(lo (read-byte str))
(deg (logior (ash (logand hi #x0f) 4) (ash (logand lo #xf0) -4)))
(b (max (min (* (- 35 deg) 17) 255) 0))
(r (max (min (* (- deg 20) 17) 255) 0)))
(analogwrite blu b)
(analogwrite red r)
(delay 500)))))
Read more details here: