Skip to content

Instantly share code, notes, and snippets.

@psychemist
Last active December 5, 2025 15:30
Show Gist options
  • Select an option

  • Save psychemist/b7f07cf0e0d3e746f08edd45aad911a0 to your computer and use it in GitHub Desktop.

Select an option

Save psychemist/b7f07cf0e0d3e746f08edd45aad911a0 to your computer and use it in GitHub Desktop.
Arduinnon Starter Project 7
// set up array of 6 integers representing frequencies
int notes[] = [ 262, 294, 330, 349];
void setup() {
// begin serial communnication
Serial.begin(9600);
}
void loop() {
// read analog value and send to serial monitor
int keyVal = analogRead(A0);
Serial.print(keyVal);
// determine what note to play based on specified condition
if ( keyVal == 1023 ) {
tone(8, notes[0]);
}
else if ( keyVal >= 990 && keyVal <= 1010 ) {
tone(8, notes[1]);
}
else if ( keyVal >= 505 && keyVal <= 515 ) {
tone(8, notes[2]);
}
else if ( keyVal >= 5 && keyVal <= 10 ) {
tone(8, notes[3]);
}
else {
noTone[8];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment