Skip to content

Instantly share code, notes, and snippets.

@samaaron
Created October 24, 2011 15:56
Show Gist options
  • Save samaaron/1309367 to your computer and use it in GitHub Desktop.
Save samaaron/1309367 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
(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