From fbb8643cad98643b0d2b86c946bff9ff5f2fedbc Mon Sep 17 00:00:00 2001 From: xixebombilla Date: Thu, 20 Feb 2014 11:50:43 -0600 Subject: [PATCH] cattoy --- examples/cattoy/cattoy.litcoffee | 44 ++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 examples/cattoy/cattoy.litcoffee diff --git a/examples/cattoy/cattoy.litcoffee b/examples/cattoy/cattoy.litcoffee new file mode 100644 index 0000000..b17e083 --- /dev/null +++ b/examples/cattoy/cattoy.litcoffee @@ -0,0 +1,44 @@ +# Cattoy + +First, let's import Cylon: + + Cylon = require '../..' + +Now that we have Cylon imported, we can start defining our robot + + Cylon.robot + +Let's define the connections and devices: + + connections: [ + {name: 'digispark', adaptor: 'digispark'}, + {name: 'leapmotion', adaptor: 'leapmotion', port: '127.0.0.1:6437'} + ] + + devices: [ + {name: 'servo1', driver: 'servo', pin: 0, connection: 'digispark'}, + {name: 'servo2', driver: 'servo', pin: 1, connection: 'digispark'}, + {name: 'leapmotion', driver: 'leapmotion', connection: 'leapmotion'} + ] + +Now that Cylon knows about the necessary hardware we're going to be using, we'll +tell it what work we want to do: + + work: (my) -> + my['x'] = 90 + my['z'] = 90 + + my.leapmotion.on 'hand', (hand) -> + my['x'] = hand.palmX.fromScale(-300, 300).toScale(30, 150) + my['z'] = hand.palmZ.fromScale(-300, 300).toScale(30, 150) + + every 100, -> + my.servo1.angle my['x'] + my.servo2.angle my['z'] + + console.log "Current Angle: #{my.servo1.currentAngle()}, #{my.servo2.currentAngle()}" + +Now that our robot knows what work to do, and the work it will be doing that +hardware with, we can start it: + + .start()