Created
September 27, 2016 22:19
-
-
Save TwoTau/46b6d86762275f65c824be4aed8a9483 to your computer and use it in GitHub Desktop.
Shows how to use sensors with RobotC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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