Hackster is hosting Hackster Holidays, Finale: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Tuesday!Stream Hackster Holidays, Finale on Tuesday!
Jordan Crouse
Published © CC BY

Utah Fight Song Button

I spend a lot of time alone watching my team play so I made a gadget that plays the fight song when they score.

BeginnerFull instructions provided508
Utah Fight Song Button

Things used in this project

Story

Read more

Schematics

Wiring for Micro Amp and LED

Schematic showing the wiring for the micro amp and LED on the MicroSD shield.

Code

utahbutton.ino

Arduino
Arduino code for playing the Utah fight song on demand.
#define SD_ChipSelectPin 8

#include <pcmRF.h>
#include <TMRpcm.h>
#include <pcmConfig.h>

#include <SD.h>

TMRpcm tmrpcm;

int LED = 4;
int button = 7;

void setup() {
  
  // Set the speaker pin 
  tmrpcm.speakerPin = 9;
  
  Serial.begin(115200);

  // Set the chip select as output per recommendation
  pinMode(8, OUTPUT);
  
  pinMode(LED, OUTPUT);
  
  // Turn the LED off
  analogWrite(LED, 0);
  
  pinMode(button, INPUT_PULLUP);
 
  // Set up the SD card
  if (!SD.begin(SD_ChipSelectPin)) {
    Serial.println("SD fail");
    return;
  }
 
  Serial.println("Here we go");
}

void loop() {
  
  if (digitalRead(button) == LOW) {
    goUtes();
  }
}

void goUtes() {
  
  // debounce the button
   delay(25);
   
   // Wait for the user to stop pressing the button
   while(digitalRead(button) == LOW);
   
   Serial.println("#goutes");
   
   // Turn the LED on
   analogWrite(LED, 255);

   tmrpcm.volume(1);
   tmrpcm.setVolume(4);
   
   // Play the song
   tmrpcm.play("utahman.wav");

   while(tmrpcm.isPlaying() == 1);

   tmrpcm.disable();

   Serial.println("That was fun");
   
   // Turn the LED off
  analogWrite(LED, 0);
}

Credits

Jordan Crouse
1 project • 0 followers

Comments