 
     @config.pins, (pin) =>
       try
-        @_setPinMode pin.number, pin.action
+        @_setPinAction pin
       catch error
         @emit 'error', error
 


  _broadcastPins: =>
    pins = _.compact _.map(@config.pins, @_readPin)
    @emit 'message',
      version: 1
      topic: 'action'
      pins: pins
      response: true

  _clearPins: =>
    _.times 19, _setDigitalWrite

    gpio = new mraa.Gpio pinNumber
    gpio.read()

  _digitalWrite: (pinNumber, value) =>
    gpio = new mraa.Gpio pinNumber
    gpio.write value

  _emitPins: (pins) =>
    @emit 'message',
      version: 1
      topic: 'action'
      pins: pins
      response: true

  _setPwmWrite: (pinNumber, value) =>
    pwm = mraa.Pwm(pinNumber)
    pwm.write value / 255.0

  _processPin: (pin) =>
    @_setPinAction pin
    return @_readPin(pin) ? @_writePin(pin)

  _readPin: (pin) =>
    return unless _.contains ['digitalRead', 'analogRead'], pin.action

    value = @_digitalRead pin.number if pin.action == 'digitalRead'
    value = @_analogRead pin.number if pin.action == 'analogRead'

    {
      action: pin.action
      number: pin.number
      value:  value
    }

  _setPinAction: (pin) =>
    return @_setDigitalRead pin.number  if pin.action == 'digitalRead'
    return @_setDigitalWrite pin.number if pin.action == 'digitalWrite'
    return @_setAnalogRead pin.number   if pin.action == 'analogRead'
    return @_setPwmWrite pin.number     if pin.action == 'pwmWrite'

  _setAnalogRead: (pinNumber) =>
    aio = new mraa.Aio pinNumber
