Hi there all,
I’ve just started learning c++ within the arduino IDE.
Trying to get my teensy v3.1 to playback 3 different sound files.
The first to be played once when the button is pushed in.
The second to then be played in a loop while the button is held down.
The third to be played once when the button is released.
Btw I’m not actually using the Audio shield.
The board is being powered by a 3v coin cell as is the miniature amplifier.
My code compiles but doesn’t seem to work as desired.
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include “mngs1.h”
#include “mngs2.h”
#include “mngs3.h”
AudioPlayMemory gunSound; // creates the Audio memory object
AudioOutputAnalog dac; // play to on-chip DAC
AudioConnection c1(gunSound, 0, dac, 0);
AudioControlSGTL5000 audioShield;
int inPin = 2;
int val = 0;
void setup()
{
pinMode(2, INPUT); //Sets the digital pin as input:
AudioMemory(1); //Allocates 1 memory spaces for audio file to be played
// turn on the output
audioShield.enable();
audioShield.volume(0.5);
}
void loop()
{
val = (digitalRead(inPin));
if (val == HIGH)
{
gunSound.play(mngs1);
}
if (!gunSound.isPlaying())
{
val = (digitalRead(inPin));
while (val == HIGH)
{
if (gunSound.isPlaying())
{
val = (digitalRead(inPin));
}
gunSound.play(mngs2);
}
}
if (val == LOW)
{
gunSound.play(mngs3);
}
};
Please let me know if I’ve made any booboos with what I’m trying to achieve.