Last active
December 5, 2025 15:30
-
-
Save psychemist/b7f07cf0e0d3e746f08edd45aad911a0 to your computer and use it in GitHub Desktop.
Arduinnon Starter Project 7
This file contains hidden or 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
| // 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