Working version with digital inputs