Hi,
I am running a little audio application where a button press triggers an audio file to play. This works fine - with the bounce library, bounce2 though triggers two plays of the audio file - any ideas why?
My second problem is that to save on a microcontroller I added a DRV8825 stepper driver to rotate a platform at 10 RPM - which works fine on it's own, but as soon as I try and merge the two sketches the motor just stalls. I'm assuming this is because the Audio library is changing the timers etc? I did only use pins that are not being used by the Audio Shield.
Is there any chance of getting this to work or should I focus elsewhere?
Thanks,
Chris
I am running a little audio application where a button press triggers an audio file to play. This works fine - with the bounce library, bounce2 though triggers two plays of the audio file - any ideas why?
My second problem is that to save on a microcontroller I added a DRV8825 stepper driver to rotate a platform at 10 RPM - which works fine on it's own, but as soon as I try and merge the two sketches the motor just stalls. I'm assuming this is because the Audio library is changing the timers etc? I did only use pins that are not being used by the Audio Shield.
Is there any chance of getting this to work or should I focus elsewhere?
Thanks,
Chris
Code:
// Simple WAV file player 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
//
// 2: Digital S/PDIF - Connect pin 22 to a S/PDIF transmitter
// https://www.oshpark.com/shared_projects/KcDBKHta
//
// 3: Analog DAC - Connect the DAC pin to an amplified speaker
// http://www.pjrc.com/teensy/gui/?info=AudioOutputAnalog
//
// To configure the output type, first uncomment one of the three
// output objects. If not using the audio shield, comment out
// the sgtl5000_1 lines in setup(), so it does not wait forever
// trying to configure the SGTL5000 codec chip.
//
// The SD card may connect to different pins, depending on the
// hardware you are using. Uncomment or configure the SD card
// pins to match your hardware.
//
// Data files to put on your SD card can be downloaded here:
// http://www.pjrc.com/teensy/td_libs_AudioDataFiles.html
//
// This example code is in the public domain.
/*
* Microstepping demo
*
* This requires that microstep control pins be connected in addition to STEP,DIR
*
* Copyright (C)2015 Laurentiu Badea
*
* This file may be redistributed under the terms of the MIT license.
* A copy of this license has been included with this distribution in the file LICENSE.
*/
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
#include <Bounce.h>
#define BUTTON 8
#define BUTTON1 16
Bounce bouncer = Bounce( BUTTON,5 );
Bounce bouncer1 = Bounce( BUTTON1,5 );
int pressed = 1;
int pressed1 = 1;
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
//--MOTOR BEGIN--//
#include <Arduino.h>
// Motor steps per revolution. Most steppers are 200 steps or 1.8 degrees/step
#define MOTOR_STEPS 200
#define RPM 10
#define DIR 21
#define STEP 20
#define ENABLE 5 // optional (just delete ENABLE from everywhere if not used)
/*
* Choose one of the sections below that match your board
*/
#include "DRV8825.h"
#define MODE0 4
#define MODE1 3
#define MODE2 2
DRV8825 stepper(MOTOR_STEPS, DIR, STEP, ENABLE, MODE0, MODE1, MODE2);
//--MOTOR END--//
void setup() {
//Serial.begin(9600);
pinMode(BUTTON, INPUT_PULLUP);
pinMode(BUTTON1, INPUT_PULLUP);
AudioMemory(8);
sgtl5000_1.enable();
sgtl5000_1.volume(0.5);
SPI.setMOSI(SDCARD_MOSI_PIN);
SPI.setSCK(SDCARD_SCK_PIN);
if (!(SD.begin(SDCARD_CS_PIN)))
{
while (1)
{
// Serial.println("Unable to access the SD card");
// delay(500);
}
}
stepper.begin(RPM);
stepper.enable();
}
void loop() {
stepper.setMicrostep(8);
stepper.move(8 * MOTOR_STEPS);
bouncer.update ( );
pressed = bouncer.read();
bouncer1.update ( );
pressed1 = bouncer1.read();
if (!pressed)
{
playFile("WAV1.WAV");
}
if (!pressed1)
{
playFile("WAV2.WAV");
}
}
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);
pressed=1;
// A brief delay for the library read WAV info
// delay(5);
// Simply wait for the file to finish playing.
while (playWav1.isPlaying())
{
// Serial.println(pressed);
// Serial.println("---");
}
}