#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);
uint8_t ROWS = 7; // 7 rows
uint8_t 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}
};
uint8_t rowPins[ROWS] = {33,34,35,36,37,38,39}; //connect to the row pinouts of the kpd
uint8_t 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();
}