     (((:trans sm) (:state sm)) m)))
 
 
+(defmacro try-times
+  [i message & body]
+  `(loop [i# ~i]
+     (let [result#
+             (when (> i# 0)
+               (try
+                 ~@body
+                 (catch Exception e#
+                   (println ~message ":" e#)
+                   ::failed)))]
+       (if (= result# ::failed)
+         (recur (dec i#))
+         result#))))
+
+
+(defn safe-read!
+  [a]
+  (try-times 50 "Failed to read pin"
+    (read! a)))
+
+
 (defn init-state!
   [floor-btn roof-btn light-ain]
   (cond
     (closed? floor-btn) :night
     (closed? roof-btn) :day
-    (> (read! light-ain) 0.35) :day
+    (> (safe-read! light-ain) 0.35) :day
     :else :night))
 
 



(defn time-sm [state day-fn! night-fn!]
  (let [dusk 0.3
        dawn 0.4]
    {:state state
     :trans
        {:day

                               (mtr-ctrl x)))]
               (close! p))))
    (loop [time-sm time-sm]
      (recur (trans-sm! timer (safe-read! light-ain))))))


(defn play []
