arduinocc
Published © MIT

Halloween: Screaming Cakes!

We all love a good treat when it comes to Halloween, so why not add some shock and horror to your food by making it scream!

BeginnerFull instructions provided30 minutes12
Halloween: Screaming Cakes!

Things used in this project

Hardware components

Teensy 4.1
Teensy 4.1
×1
Teensy Audio Board
Teensy Audio Board
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×1
Tin Foil
×1

Software apps and online services

Microsoft Visual Studio 2022
Visual Micro

Story

Read more

Code

ScreamingCake.ino

Arduino
Main INO File for this Example
// Screaming Cake Example
//
// Three types of output may be used, by configuring the code below.
//
//   1: Digital I2S - Normally used with the audio shield:
//         http://www.pjrc.com/store/teensy3_audio.html

// This also uses the Capacitive Touch Library to detect when the food is touched
// // https://www.pjrc.com/teensy/td_libs_CapacitiveSensor.html
// 
// This example code is in the public domain.
#include <CapacitiveSensor.h>
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>

CapacitiveSensor   cs_4_2 = CapacitiveSensor(30, 31);        // 10M resistor between pins 4 & 2, pin 2 is sensor pin, add a wire and or foil if desired

AudioPlaySdWav           playWav1;
AudioOutputI2S           audioOutput;

AudioConnection          patchCord1(playWav1, 0, audioOutput, 0);
AudioConnection          patchCord2(playWav1, 1, audioOutput, 1);
AudioControlSGTL5000     sgtl5000_1;

// Use these with the Teensy Audio Shield
#define SDCARD_CS_PIN    10
#define SDCARD_MOSI_PIN  7
#define SDCARD_SCK_PIN   14

void setup() {
    Serial.begin(9600);  

    // Audio connections require memory to work.  For more
    // detailed information, see the MemoryAndCpuUsage example
    AudioMemory(8);

    // Comment these out if not using the audio adaptor board.
    // This may wait forever if the SDA & SCL pins lack
    // pullup resistors
    sgtl5000_1.enable();
    sgtl5000_1.volume(1.0);

    SPI.setMOSI(SDCARD_MOSI_PIN);
    SPI.setSCK(SDCARD_SCK_PIN);
    if (!(SD.begin(SDCARD_CS_PIN))) {
        // stop here, but print a message repetitively
        while (1) {
            Serial.println("Unable to access the SD card");
            delay(500);
        }
    }
}

void playFile(const char* filename)
{
  
    Serial.print("Playing file: ");
    Serial.println(filename);

    // Start playing the file.  This sketch continues to
    // run while the file plays.
    playWav1.play(filename);

    // A brief delay for the library read WAV info
    delay(25);

    // Simply wait for the file to finish playing.
    while (playWav1.isPlaying()) {
        // uncomment these lines if you audio shield
        // has the optional volume pot soldered
        //float vol = analogRead(15);
        //vol = vol / 1024;
        // sgtl5000_1.volume(vol);
    }
}


void loop() {
    int touchReadVal = cs_4_2.capacitiveSensor(30);
    Serial.print("Touch:");
    Serial.println(touchReadVal);
    if (touchReadVal >= 0 && touchReadVal < 30000) {
        playFile("SDTEST1.WAV");  // filenames are always uppercase 8.3 format
    }
    delay(500);

}

Credits

arduinocc
5 projects • 13 followers
Arduino compatible IDE for Microsoft Visual Studio and Atmel Studio 7 with unique USB Debugger, Trace, Pin Viewer and Plotter, GDB Debugging
Contact

Comments

Please log in or sign up to comment.