I was trying mixing codes ( Oled Display ssd_1306 + Keypad + Audio) into one sketch .
first i mixed (Oled Display SSD_1306 + Keypad) ....Display is connected SDA,SCL to Teensy 4.1 pins (18,19).
it is working , i checked. code is below
Next i made simple (Audio) code from "TeensyVariablePlayback"
i use Serial monitor to input for play .wav file, faster and slower.
it is also working . code is below
Next i Tried mixing above two code into one . and made code
but here i am getting below error in compiling,,,,,,
Detailed error is in text Attachment [error001.cpp] you can see.
i seemed pin 18,19 are used by Audio board rev d.
please check how to solve it ......
Thank you,,,,
first i mixed (Oled Display SSD_1306 + Keypad) ....Display is connected SDA,SCL to Teensy 4.1 pins (18,19).
it is working , i checked. code is below
Code:
#include <Keypad.h> // working 4x7 keypad and oled Display
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels
#define OLED_RESET -1
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
const byte ROWS = 7; // 7 rows
const byte COLS = 4; //4 columns // Analog pin_22 , Enc (2,3) ,
char keys[ROWS][COLS] = {
{1,2,3,4},
{5,6,7,8},
{9,10,11,12},
{13,14,15,16},
{17,18,19,20},
{21,22,23,24},
{25,26,27,28}
};
byte rowPins[ROWS] = {33,34,35,36,37,38,39}; //connect to the row pinouts of the kpd
byte colPins[COLS] = {40,41,14,16}; //connect to the column pinouts of the kpd
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
String msg;
void setup() {
Serial.begin(57600);
if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}
display.display();
delay(2000);
display.clearDisplay();
msg = "";
}
void loop() {
if (kpd.getKeys())
{
for (int i=0; i<LIST_MAX; i++) // Scan the whole key list.
{ int mykey = (kpd.key[i].kchar);
if ( kpd.key[i].stateChanged ) // ---------------------------------------------------------
{ switch (kpd.key[i].kstate) {
case PRESSED:
msg = " is presed"; SCN_MAIN (mykey); Serial.println(mykey); Serial.println("pressed");
break;
case RELEASED:
msg = " is Released"; SCN_MAIN (mykey); Serial.println(mykey); Serial.println("releassed");
break;
} } //-----------------------------------------------------------------------------------------------------
} }
} // End loop
void SCN_MAIN (int number) {
display.clearDisplay();
display.setTextSize(1); // Normal 1:1 pixel scale
display.setTextColor(SSD1306_WHITE); // Draw white text
display.setCursor(0, 0); // Start at top-left corner
display.print(number); display.print(msg);
display.display();
}
i use Serial monitor to input for play .wav file, faster and slower.
it is also working . code is below
Code:
// Plays a Wav (16-bit signed) PCM audio file at slower or faster rate
// this example requires an uSD-card inserted to teensy 3.6 with a file called DEMO.WAV
#include <Bounce.h>
#include <Arduino.h>
#include <Audio.h>
#include <SD.h>
#include <TeensyVariablePlayback.h>
// GUItool: begin automatically generated code
AudioPlaySdResmp playSdWav1; //xy=324,457
AudioOutputI2S i2s2; //xy=840.8571472167969,445.5714416503906
AudioConnection patchCord1(playSdWav1, 0, i2s2, 0);
AudioConnection patchCord2(playSdWav1, 0, i2s2, 1);
AudioControlSGTL5000 audioShield;
// GUItool: end automatically generated code
float Speed = 1.00;
void setup() {
Serial.begin(57600);
if (!(SD.begin(BUILTIN_SDCARD))) {
while (1) {
Serial.println("Unable to access the SD card");
delay(500);
}
}
AudioMemory(24);
audioShield.enable();
audioShield.volume(0.5);
playSdWav1.enableInterpolation(true);
}
void loop() {
// -------------------------------------------------------
if (Serial.available() > 0) {
int incomingByte = Serial.read();
if (incomingByte == 49) { // key 1
Speed = Speed + 0.01;
playSdWav1.setPlaybackRate(Speed);
Serial.println(Speed);
}
if (incomingByte == 50) { // key 2
Speed = Speed - 0.01;
playSdWav1.setPlaybackRate(Speed);
Serial.println(Speed);
}
if (incomingByte == 51) { // key 3
playSdWav1.playWav("13.WAV");
playSdWav1.setLoopType(looptype_repeat);
Serial.println("Playing 13.wav in loop mode");
}
if (incomingByte == 52) { // key 4
Serial.println("stopped");
playSdWav1.stop();
}
if (incomingByte == 53) { // key5
playSdWav1.setPlaybackRate(Speed);
Serial.println("speed 1.00");
}
} // ------------------------------------------------------
}
namespace std {
void __throw_bad_function_call() {}
void __throw_length_error(char const*) {}
}
Code:
// Plays a Wav (16-bit signed) PCM audio file at slower or faster rate
// this example requires an uSD-card inserted to teensy 3.6 with a file called DEMO.WAV
#include <Bounce.h>
#include <Arduino.h>
#include <Audio.h>
#include <SD.h>
#include <TeensyVariablePlayback.h>
#include <Keypad.h> // working 4x7 keypad and oled Display
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
// GUItool: begin automatically generated code
AudioPlaySdResmp playSdWav1; //xy=324,457
AudioOutputI2S i2s2; //xy=840.8571472167969,445.5714416503906
AudioConnection patchCord1(playSdWav1, 0, i2s2, 0);
AudioConnection patchCord2(playSdWav1, 0, i2s2, 1);
AudioControlSGTL5000 audioShield;
// GUItool: end automatically generated code
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels
#define OLED_RESET -1
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
const byte ROWS = 7; // 7 rows
const byte COLS = 4; //4 columns // Analog pin_22 , Enc (2,3) ,
char keys[ROWS][COLS] = {
{1,2,3,4},
{5,6,7,8},
{9,10,11,12},
{13,14,15,16},
{17,18,19,20},
{21,22,23,24},
{25,26,27,28}
};
byte rowPins[ROWS] = {33,34,35,36,37,38,39}; //connect to the row pinouts of the kpd
byte colPins[COLS] = {40,41,14,16}; //connect to the column pinouts of the kpd
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
String msg;
float Speed = 1.00;
void setup() {
Serial.begin(57600);
if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}
display.display();
delay(2000);
display.clearDisplay();
msg = "";
if (!(SD.begin(BUILTIN_SDCARD))) {
while (1) {
Serial.println("Unable to access the SD card");
delay(500);
}
}
AudioMemory(24);
audioShield.enable();
audioShield.volume(0.5);
playSdWav1.enableInterpolation(true);
}
void loop() {
if (kpd.getKeys())
{
for (int i=0; i<LIST_MAX; i++) // Scan the whole key list.
{ int mykey = (kpd.key[i].kchar);
if ( kpd.key[i].stateChanged ) // ---------------------------------------------------------
{ switch (kpd.key[i].kstate) {
case PRESSED:
msg = " is presed"; SCN_MAIN (mykey); Serial.println(mykey); Serial.println("pressed");
break;
case RELEASED:
msg = " is Released"; SCN_MAIN (mykey); Serial.println(mykey); Serial.println("releassed");
break;
} } //-----------------------------------------------------------------------------------------------------
} }
// -------------------------------------------------------
if (Serial.available() > 0) {
int incomingByte = Serial.read();
if (incomingByte == 49) { // key 1
Speed = Speed + 0.01;
playSdWav1.setPlaybackRate(Speed);
Serial.println(Speed);
}
if (incomingByte == 50) { // key 2
Speed = Speed - 0.01;
playSdWav1.setPlaybackRate(Speed);
Serial.println(Speed);
}
if (incomingByte == 51) { // key 3
playSdWav1.playWav("13.WAV");
playSdWav1.setLoopType(looptype_repeat);
Serial.println("Playing 13.wav in loop mode");
}
if (incomingByte == 52) { // key 4
Serial.println("stopped");
playSdWav1.stop();
}
if (incomingByte == 53) { // key5
playSdWav1.setPlaybackRate(Speed);
Serial.println("speed 1.00");
}
} // ------------------------------------------------------
}
namespace std {
void __throw_bad_function_call() {}
void __throw_length_error(char const*) {}
}
void SCN_MAIN (int number) {
display.clearDisplay();
display.setTextSize(1); // Normal 1:1 pixel scale
display.setTextColor(SSD1306_WHITE); // Draw white text
display.setCursor(0, 0); // Start at top-left corner
display.print(number); display.print(msg);
display.display();
}
Code:
Multiple libraries were found for "SD.h"
Used: C:\Program Files\Arduino\hardware\teensy\avr\libraries\SD
Not used: C:\Program Files\Arduino\libraries\SD
Multiple libraries were found for "Keypad.h"
Used: C:\Program Files\Arduino\hardware\teensy\avr\libraries\Keypad
Not used: C:\Users\acer\Documents\Arduino\libraries\Keypad-3.1.1
Using library Bounce in folder: C:\Program Files\Arduino\hardware\teensy\avr\libraries\Bounce (legacy)
Using library Audio at version 1.3 in folder: C:\Program Files\Arduino\hardware\teensy\avr\libraries\Audio
Using library SPI at version 1.0 in folder: C:\Program Files\Arduino\hardware\teensy\avr\libraries\SPI
Using library SD at version 2.0.0 in folder: C:\Program Files\Arduino\hardware\teensy\avr\libraries\SD
Using library SdFat at version 2.1.2 in folder: C:\Program Files\Arduino\hardware\teensy\avr\libraries\SdFat
Using library SerialFlash at version 0.5 in folder: C:\Program Files\Arduino\hardware\teensy\avr\libraries\SerialFlash
Using library TeensyVariablePlayback at version 1.0.16 in folder: C:\Users\acer\Documents\Arduino\libraries\TeensyVariablePlayback
Using library LittleFS at version 1.0.0 in folder: C:\Program Files\Arduino\hardware\teensy\avr\libraries\LittleFS
Using library Keypad at version 3.1.1 in folder: C:\Program Files\Arduino\hardware\teensy\avr\libraries\Keypad
Using library Wire at version 1.0 in folder: C:\Program Files\Arduino\hardware\teensy\avr\libraries\Wire
Using library Adafruit_GFX_Library at version 1.7.5 in folder: C:\Users\acer\Documents\Arduino\libraries\Adafruit_GFX_Library
Using library Adafruit_SSD1306 at version 2.5.7 in folder: C:\Users\acer\Documents\Arduino\libraries\Adafruit_SSD1306
reference to 'byte' is ambiguous
i seemed pin 18,19 are used by Audio board rev d.
please check how to solve it ......
Thank you,,,,