Hello,
I have a strange behavior with using a Teensy 3.2 in combination with the audio board and the following code:
------------------------------------------------------------------------------------------------------------------------
#include <Bounce.h>
Bounce button0 = Bounce(0, 10);
Bounce button1 = Bounce(1, 10);
// libraries for Teensy and Teens Audio Shield
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
// https://www.pjrc.com/teensy/gui/index.html?info=AudioAnalyzePeak#
// GUItool: begin automatically generated code
AudioPlaySdWav playSdWav1; //xy=224,134
AudioAnalyzePeak peak1; //xy=518,232
AudioAnalyzePeak peak2; //xy=526,311
AudioOutputI2S i2s1; //xy=837,146
AudioConnection patchCord1(playSdWav1, 0, i2s1, 0);
AudioConnection patchCord2(playSdWav1, 0, peak1, 0);
AudioConnection patchCord3(playSdWav1, 1, i2s1, 1);
AudioConnection patchCord4(playSdWav1, 1, peak2, 0);
AudioControlSGTL5000 sgtl5000_1; //xy=342,534
// GUItool: end automatically generated code
// Use these Pins 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);
delay(500);
AudioMemory(10);
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);
}
}
delay(1000);
pinMode(0, INPUT);
pinMode(1, INPUT);
}
elapsedMillis msecs;
void loop() {
testenc();
if (playSdWav1.isPlaying() == false) {
Serial.println("Start playing");
//playSdWav1.play("SDTEST1.WAV");
//playSdWav1.play("SDTEST2.WAV");
//playSdWav1.play("SDTEST3.WAV");
playSdWav1.play("SDTEST4.WAV");
delay(10); // wait for library to parse WAV info
}
if (msecs > 15) {
if (peak1.available() && peak2.available()) {
msecs = 0;
float leftNumber = peak1.read();
float rightNumber = peak2.read();
//Serial.print(leftNumber);
//Serial.print(", ");
//Serial.print(rightNumber);
//Serial.println();
}
}
}
void testenc()
{
button0.update();
button1.update();
if (button0.fallingEdge()) { Serial.println("button 0 fallingEdge"); }
if (button1.fallingEdge()) { Serial.println("button 1 fallingEdge"); }
if (button0.risingEdge()) { Serial.println("button 0 risingEdge"); }
if (button1.risingEdge()) { Serial.println("button 1 risingEdge"); }
}
-------------------------------------------------------------------------------------------
using this combination the output on the serial port is like:
-------------------------------------------------------------------------------------------
...
button 1 fallingEdge
button 1 risingEdge
button 1 fallingEdge
button 1 risingEdge
button 1 fallingEdge
button 1 risingEdge
button 1 fallingEdge
...
-------------------------------------------------------------------------------------------
but no response from the button0!
When I use only the Teensy 3.2 WITHOUT the audioshield everything works as expected with the following 'naked' code:
-------------------------------------------------------------------------------------------
#include <Bounce.h>
Bounce button0 = Bounce(0, 10);
Bounce button1 = Bounce(1, 10);
void setup() {
Serial.begin(9600);
Serial.println("Encoder Test:");
pinMode(0, INPUT);
pinMode(1, INPUT);
}
void loop() {
testenc();
}
void testenc()
{
button0.update();
button1.update();
if (button0.fallingEdge()) {
Serial.println("button 0 fallingEdge");
//Keyboard.print("-");
}
if (button1.fallingEdge()) {
Serial.println("button 1 fallingEdge");
//Keyboard.print("+");
}
if (button0.risingEdge()) {
Serial.println("button 0 risingEdge");
//Keyboard.print("+");
}
if (button1.risingEdge()) {
Serial.println("button 1 risingEdge");
//Keyboard.print("+");
}
}
-------------------------------------------------------------------------------------------
and the expected result is:
-------------------------------------------------------------------------------------------
...
button 0 fallingEdge
button 1 fallingEdge
button 1 risingEdge
button 0 risingEdge
button 1 fallingEdge
button 1 risingEdge
button 0 fallingEdge
button 1 fallingEdge
button 0 risingEdge
button 0 fallingEdge
button 1 risingEdge
button 0 risingEdge
button 1 fallingEdge
button 0 fallingEdg
...
++++++++++++++++++++
So my rotary encoder obviously is ok.
What am I missing?
I have a strange behavior with using a Teensy 3.2 in combination with the audio board and the following code:
------------------------------------------------------------------------------------------------------------------------
#include <Bounce.h>
Bounce button0 = Bounce(0, 10);
Bounce button1 = Bounce(1, 10);
// libraries for Teensy and Teens Audio Shield
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
// https://www.pjrc.com/teensy/gui/index.html?info=AudioAnalyzePeak#
// GUItool: begin automatically generated code
AudioPlaySdWav playSdWav1; //xy=224,134
AudioAnalyzePeak peak1; //xy=518,232
AudioAnalyzePeak peak2; //xy=526,311
AudioOutputI2S i2s1; //xy=837,146
AudioConnection patchCord1(playSdWav1, 0, i2s1, 0);
AudioConnection patchCord2(playSdWav1, 0, peak1, 0);
AudioConnection patchCord3(playSdWav1, 1, i2s1, 1);
AudioConnection patchCord4(playSdWav1, 1, peak2, 0);
AudioControlSGTL5000 sgtl5000_1; //xy=342,534
// GUItool: end automatically generated code
// Use these Pins 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);
delay(500);
AudioMemory(10);
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);
}
}
delay(1000);
pinMode(0, INPUT);
pinMode(1, INPUT);
}
elapsedMillis msecs;
void loop() {
testenc();
if (playSdWav1.isPlaying() == false) {
Serial.println("Start playing");
//playSdWav1.play("SDTEST1.WAV");
//playSdWav1.play("SDTEST2.WAV");
//playSdWav1.play("SDTEST3.WAV");
playSdWav1.play("SDTEST4.WAV");
delay(10); // wait for library to parse WAV info
}
if (msecs > 15) {
if (peak1.available() && peak2.available()) {
msecs = 0;
float leftNumber = peak1.read();
float rightNumber = peak2.read();
//Serial.print(leftNumber);
//Serial.print(", ");
//Serial.print(rightNumber);
//Serial.println();
}
}
}
void testenc()
{
button0.update();
button1.update();
if (button0.fallingEdge()) { Serial.println("button 0 fallingEdge"); }
if (button1.fallingEdge()) { Serial.println("button 1 fallingEdge"); }
if (button0.risingEdge()) { Serial.println("button 0 risingEdge"); }
if (button1.risingEdge()) { Serial.println("button 1 risingEdge"); }
}
-------------------------------------------------------------------------------------------
using this combination the output on the serial port is like:
-------------------------------------------------------------------------------------------
...
button 1 fallingEdge
button 1 risingEdge
button 1 fallingEdge
button 1 risingEdge
button 1 fallingEdge
button 1 risingEdge
button 1 fallingEdge
...
-------------------------------------------------------------------------------------------
but no response from the button0!
When I use only the Teensy 3.2 WITHOUT the audioshield everything works as expected with the following 'naked' code:
-------------------------------------------------------------------------------------------
#include <Bounce.h>
Bounce button0 = Bounce(0, 10);
Bounce button1 = Bounce(1, 10);
void setup() {
Serial.begin(9600);
Serial.println("Encoder Test:");
pinMode(0, INPUT);
pinMode(1, INPUT);
}
void loop() {
testenc();
}
void testenc()
{
button0.update();
button1.update();
if (button0.fallingEdge()) {
Serial.println("button 0 fallingEdge");
//Keyboard.print("-");
}
if (button1.fallingEdge()) {
Serial.println("button 1 fallingEdge");
//Keyboard.print("+");
}
if (button0.risingEdge()) {
Serial.println("button 0 risingEdge");
//Keyboard.print("+");
}
if (button1.risingEdge()) {
Serial.println("button 1 risingEdge");
//Keyboard.print("+");
}
}
-------------------------------------------------------------------------------------------
and the expected result is:
-------------------------------------------------------------------------------------------
...
button 0 fallingEdge
button 1 fallingEdge
button 1 risingEdge
button 0 risingEdge
button 1 fallingEdge
button 1 risingEdge
button 0 fallingEdge
button 1 fallingEdge
button 0 risingEdge
button 0 fallingEdge
button 1 risingEdge
button 0 risingEdge
button 1 fallingEdge
button 0 fallingEdg
...
++++++++++++++++++++
So my rotary encoder obviously is ok.
What am I missing?