Skip to content

Instantly share code, notes, and snippets.

@mikkoelo
Created March 14, 2018 21:07
Show Gist options
  • Save mikkoelo/be29ea74fab324ae901697fe2ac7eb59 to your computer and use it in GitHub Desktop.
Save mikkoelo/be29ea74fab324ae901697fe2ac7eb59 to your computer and use it in GitHub Desktop.
void setup()
{
//initialize serial communications at a 9600 baud rate
Serial.begin(9600);
}
void loop()
{
// read and round the value from pin 0
float num = analogRead(0);
int distance = analogRead(1);
int buzzer = map(distance, 0, 2013, 100, 2000);
num = round(num);
int rounded = (int) num;
tone(8, buzzer);
//send the rounded value over the serial port
Serial.println(rounded);
Serial.println(distance);
delay(100);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment