Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* Pleasedontcode.com **********
- Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- - Terms and Conditions:
- You have a non-exclusive, revocable, worldwide, royalty-free license
- for personal and commercial use. Attribution is optional; modifications
- are allowed, but you're responsible for code maintenance. We're not
- liable for any loss or damage. For full terms,
- please visit pleasedontcode.com/termsandconditions.
- - Project: Audio Control
- - Source Code NOT compiled for: Arduino Uno
- - Source Code created on: 2024-10-31 04:48:44
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* When the tail is twisted more than 100 degrees */
- /* back or forth, one of three random audio files */
- /* needs to play through Processing. The ability to */
- /* twist the tail backwards or forwards to play one */
- /* of the three random audio files needs to reset */
- /* each time */
- /****** END SYSTEM REQUIREMENTS *****/
- /****** DEFINITION OF LIBRARIES *****/
- #include <Audio.h> // Include the Audio library for audio playback
- #include <Random.h> // Include the Random library for random number generation
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- /***** DEFINITION OF ANALOG INPUT PINS *****/
- const uint8_t tail_Potentiometer_Vout_PIN_A0 = A0;
- // Audio file names
- const char* audioFiles[] = {"audio1.wav", "audio2.wav", "audio3.wav"}; // Array of audio file names
- // Audio object
- AudioPlayMemory playMem; // Create an audio play object
- AudioOutputI2S audioOutput; // Create an audio output object
- AudioConnection patchCord(playMem, 0, audioOutput, 0); // Connect the audio play object to the output
- // Variable to store the last position of the potentiometer
- int lastPotValue = 0;
- void setup(void)
- {
- // put your setup code here, to run once:
- pinMode(tail_Potentiometer_Vout_PIN_A0, INPUT); // Set the potentiometer pin as input
- AudioMemory(8); // Allocate memory for audio processing
- }
- void loop(void)
- {
- // Read the potentiometer value
- int potValue = analogRead(tail_Potentiometer_Vout_PIN_A0);
- // Map the potentiometer value to an angle (0-1023 to 0-180 degrees)
- float angle = map(potValue, 0, 1023, 0, 180);
- // Check if the angle exceeds 100 degrees
- if (angle > 100 && lastPotValue <= 100) {
- // Play a random audio file
- int randomIndex = random(0, 3); // Generate a random index (0 to 2)
- playMem.play(audioFiles[randomIndex]); // Play the selected audio file
- }
- // Reset the last potentiometer value if the angle is less than or equal to 100
- if (angle <= 100) {
- lastPotValue = angle; // Update the last potentiometer value
- }
- // Allow audio processing to run
- delay(100); // Small delay to avoid rapid triggering
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement