Created
June 20, 2012 20:23
-
-
Save ardumont/2962001 to your computer and use it in GitHub Desktop.
blink a led in morse according to a letter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; time | |
(def short-pulse 100) | |
(def long-pulse 250) | |
(def letter-delay 500) | |
;; pin number | |
(def pin-led 13) | |
(defn blink "Given a board and time, make the led blink a given time" | |
[board time] | |
(digital-write board pin-led HIGH) | |
(Thread/sleep time) | |
(digital-write board pin-led LOW) | |
(Thread/sleep time)) | |
(defmulti blink-letter-morse "Given a bit, blink the led accordingly in morse" (fn [board bit] bit)) | |
(defmethod blink-letter-morse 0 [board _] (blink board short-pulse)) | |
(defmethod blink-letter-morse 1 [board _] (blink board long-pulse)) | |
(defn blink-letter "Given a letter in morse representation, make the led blink accordingly (0 short pulse ; 1 long pulse)" | |
[board letter-in-morse] | |
(doseq [bit letter-in-morse] (blink-letter-morse board bit)) | |
(Thread/sleep letter-delay)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment