Skip to content

Instantly share code, notes, and snippets.

@Maxbotix
Last active March 8, 2024 05:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Maxbotix/b417753919ce736d4ef31f46aa73f313 to your computer and use it in GitHub Desktop.
Save Maxbotix/b417753919ce736d4ef31f46aa73f313 to your computer and use it in GitHub Desktop.
const int anPin = 0;
long anVolt, cm;
void setup() {
Serial.begin(9600);
}
void read_sensor(){
anVolt = analogRead(anPin);
cm = anVolt/2;
}
void print_range(){
Serial.print(“Range = ”);
Serial.print(cm);
Serial.print(” cm “);
Serial.print('\n');
}
void loop() {
read_sensor();
print_range();
delay(100);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment