Skip to content

Instantly share code, notes, and snippets.

@TwoTau
Created September 27, 2016 22:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TwoTau/46b6d86762275f65c824be4aed8a9483 to your computer and use it in GitHub Desktop.
Save TwoTau/46b6d86762275f65c824be4aed8a9483 to your computer and use it in GitHub Desktop.
Shows how to use sensors with RobotC
#pragma config(Hubs, S1, HTMotor, HTServo, none, none)
#pragma config(Motor, mtr_S1_C1_1, leftWheel, tmotorTetrix, openLoop, driveLeft)
#pragma config(Motor, mtr_S1_C1_2, rightWheel, tmotorTetrix, openLoop, driveRight)
#pragma config(Sensor, S2, gyroscope, sensorI2CHiTechnicGyro)
#pragma config(Sensor, S3, sonar, sensorSONAR)
#pragma config(Sensor, S4, compass, sensorI2CHiTechnicCompass)
int getCompass() {
return SensorValue[compass];
}
int getSonar() {
return SensorValue[sonar];
}
int getGyro() {
int defaultGyroValue = 0; // what the gyro value is in the beginning
return(SensorValue[gyroscope] - defaultGyroValue);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment