module main
author unknown
version 1 0 
description ''

  spec ' ' 'Fan Motor' 'Fan Motor Pin _ to Turn Off' 'num' 17
  spec ' ' 'Fan Motor Pin' 'Fan Motor Pin _ Direction _ Speed _' 'num bool auto' 17 true 50

to 'Fan Motor' Pin {
  digitalWriteOp (Pin + 1) false
  digitalWriteOp (Pin + 2) false
}

to 'Fan Motor Pin' Pin Direction Speed {
  if (and (Speed > 0) (Speed <= 100)) {
    local 'PWM' (absoluteValue (((Speed - 1) * ((1023 - 1) / 99)) + 1))
    if (Direction == (booleanConstant false)) {
      if (and (PWM > 0) (PWM < 1024)) {
        digitalWriteOp (Pin + 1) true
        analogWriteOp (Pin + 2) (1023 - PWM)
      }
    } else {
      if (and (PWM > 0) (PWM < 1024)) {
        digitalWriteOp (Pin + 1) false
        analogWriteOp (Pin + 2) PWM
      }
    }
  }
}

script 50 168 {
to 'Fan Motor' {}
}

script 66 341 {
to 'Fan Motor Pin' {}
}


module Spark_PWM Control
author 'Fab Lab'
version 1 0 
description ''

  spec ' ' 'FanMotor' 'FanMotor Pin _ Direction _ Speed _' 'num bool num' 17 true 50
  spec ' ' 'FanMotor2' 'FanMotor Pin _ to Turn Off' 'auto' 18

to FanMotor Pin Direction Speed {
}

to FanMotor2 Pin {
}

