Example #1
0
float gyro(int samples) {
  float value = 0;
  for (int i = 0; i < samples; i++) {
    value += GYRO.getAngularDisplacement();
    GYRO.update();
    delayMicroseconds(10);
  }
  return value / samples;
}
Example #2
0
void loop() {
  GYRO.update();
  
  if (Serial.available()) {
    char in = Serial.read();
    switch (in) {
      case 'l':
        turn(10, SPEED);
        break;
      case 'r':
        turn(10, -SPEED);
        break;
      case 'f':
        MOTORS.setMotorSpeed(SPEED, SPEED);
        break;
      case 'b':
        MOTORS.setMotorSpeed(-SPEED, -SPEED);
        break;
      case 's':
        MOTORS.setMotorSpeed(0, 0);
        break;
    }
  }
}