 
 
 app.get '/toggle/18', (req, res) ->
-  if gpio18.state == 0
-    gpio18.set()
+  if io[18].state == 0
+    io[18].set()
   else
-    gpio18.reset()
-  res.send("toggled to #{gpio18.state == 0 ? 'on' : 'off'}")
+    io[18].reset()
+  res.send("toggled to #{io[18].state == 0 ? 'on' : 'off'}")
 
 
-gpio18.on 'change', (val) ->
+io[18].on 'change', (val) ->
   # value will report either 1 or 0 (number) when the value changes
-   gpio18.state = val
+   io[18].state = val
 
 
-gpio22.on 'change', (val) ->
+io[22].on 'change', (val) ->
   console.log "22 changed to #{val}"
 
-gpio22.on 'change', (val) ->
-  gpio23.set(val)
+io[22].on 'change', (val) ->
+  io[23].set(val)
 
 
 app.listen app.get('port'), ->



app.get '/on/18', (req, res) ->
  gpio18.set()
  res.send('on')


app.get '/off/18', (req, res) ->
  gpio18.reset()
  clearInterval beatsInterval
  res.send('off')

app.get '/beats/18', (req, res) ->
  beatsInterval = setInterval ->
    gpio18.set()
    setTimeout ->
      gpio18.reset()
    , 200
  , 1000
  res.send('beats started')

express = require 'express'
gpio = require 'gpio'
app = express()

io = {
  18: gpio.export 18
  23: gpio.export 23
  22: gpio.export 22, {
     direction: 'in'
  }
}

beatsInterval = null
