Skip to content

Instantly share code, notes, and snippets.

@techtide
Last active January 21, 2019 16:04
Show Gist options
  • Save techtide/aa1e25481c6c263a08acc13b763f1af1 to your computer and use it in GitHub Desktop.
Save techtide/aa1e25481c6c263a08acc13b763f1af1 to your computer and use it in GitHub Desktop.
how to use ultrasonic
/* wot is the ultrasonic sensor
* sends ultrasonic pulses
* https://i0.wp.com/randomnerdtutorials.com/wp-content/uploads/2013/11/How-ultrasonic-sensor-works.jpg?resize=700%2C470&ssl=1
* this is sample subsystem
*/
import edu.wpi.first.wpilibj.Ultrasonic;
Ultrasonic ultra = new Ultrasonic(1,1); // c ultrasonic sensor which uses DOut 1
// the echo pulse and DigitalInput 1 for the trigger pulse
public void robotInit() {
ultra.setAutomaticMode(true); // turns on automatic mode
}
public double getRange() {
double range = ultra.getRangeInches(); // reads the range on the ultra. sesnor
return range;
// then you measure the things physically
// and then you check for te range
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment