-
-
Save philandstuff/1579825 to your computer and use it in GitHub Desktop.
Simple coordinated ping mechanism - only plays the ping if two buttons are pressed at the "same" time
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
(ns examples.coordination | |
(:use [overtone.live] | |
[overtone.inst.synth]) | |
(:require [polynome.core :as poly])) | |
;;ping | |
(def m (poly/init "/dev/tty.usbserial-m64-0790")) | |
(poly/on-press m (fn [x y s] | |
(println "pressed " [x y]) | |
(let [t (now)] | |
(if (and (= 7 x) | |
(= 0 y)) | |
(if-let [event (poly/find-event s #(and (= 0 (:x %)) | |
(= 0 (:y %))))] | |
(when (and (< (:time event) t) | |
(< (- t (:time event)) 100)) | |
(println "ping") | |
(ping))))))) | |
(poly/on-press m (fn [x y s] | |
(let [t (now)] | |
(if (and (= 0 x) | |
(= 0 y)) | |
(if-let [event (poly/find-event s #(and (= 7 (:x %)) | |
(= 0 (:y %))))] | |
(when (and (< (:time event) t) | |
(< (- t (:time event)) 100)) | |
(println "ping") | |
(ping))))))) | |
(poly/remove-all-callbacks m) | |
(poly/disconnect m)l |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment