![]() Int button3 = 3 int frequency = 0 const int delayTime = 500 //Set up a constant for the variable of delay time in the tone() function. Int sensorValue = 0 int button1 = 5 //Set up the input pins connected to the buttons. Int sensorPin = 0 //Set up pin connected to the sensor (the potentiometer). ![]() int piezoPin = 8 //Set up pin connected to Piezo. Check out the code that I used to create the three-button piano here or check below. These can be changed! Play around with different frequency values to see what different sounds you can get from the piezo. Within the if/else statements, map() functions are used to map the scale of the potentiometer onto a set of frequencies. There's some if/else statements set up to tell the Arduino what to do if different buttons are pressed as well as to set it up with "frequency = 0" in situations when none of the buttons are being pressed. You'll also notice that the code features two other bits of code. The "frequency" component of the tone function is what can be thought of as "the sound" that is being produced by the buzzer. The third component (duration) is optional, while the other two are necessary for the buzzer to function.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |