Пример #1
0
void ShaftEncoder::boot(){
  baseTime = millis();
  counter = 0;
  rotation = 0;
  timeOfRotation = INFINITY;
  state = analogToDigital(analogRead(bbId));
  init = true;
}
Пример #2
0
float DigitalOut::put(float value) {
  // Make sure value is in [0, 1].
	value = constrain(value, 0, 1);
  // Set ON status depending on value: invert if mode is SINK.
  _isOn = analogToDigital(value);
  // Write to output.
  digitalWrite(_pin, _isOn ^ (_mode == SOURCE) ? LOW : HIGH);
  // Return value.
  return value;
}
Пример #3
0
void ShaftEncoder::read(){
  int s = analogToDigital(analogRead(bbId));
  if(s == LOW && state == HIGH){
    counter++;
    if(counter % spr == 0){
        rotation++;
    }
    timeOfRotation = millis()-baseTime;
    baseTime = millis();
    
    init = false;
  }
  state = s;
}