Skip to content

Instantly share code, notes, and snippets.

@mgamba
Last active June 30, 2020 23:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mgamba/9dda25cbf55b046edfe6297ca57629b1 to your computer and use it in GitHub Desktop.
Save mgamba/9dda25cbf55b046edfe6297ca57629b1 to your computer and use it in GitHub Desktop.
Example ino file for using MQSL and MOSI/CS at the same time
// This uses the Adafruit ST7735 tft display and teensy 4.0
// audio out -> teensy pin mappings
/*
+ -> 12
- -> GND
*/
// tft -> teensy pin mappings:
/*
Vin -> 3.3V (next to VBat)
Gnd -> GND
SCK -> 13 (SCK)
SI -> 11 (MOSI)
TCS -> 10 (CS)
RST -> 8 (PWM)
DC -> 9 (PWM)
*/
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
#include <Adafruit_ST7735.h>
#include <SPI.h>
#define TFT_MOSI 11
#define TFT_SCK 13
#define TFT_DC 9
#define TFT_CS 10
#define TFT_RST 8
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
float sweep_seconds = 3; // Length of time for the sweep in seconds
void setup(void)
{
// Wait for at least 3 seconds for the USB serial connection
Serial.begin (9600);
while (!Serial && millis () < 3000);
tft.initR(INITR_144GREENTAB); // ST7735R
AudioMemory (8);
Serial.println ("setup done");
AudioSynthToneSweep tonesweep;
AudioMixer4 mixer1;
unsigned prev_pin10_config = CORE_PIN10_CONFIG; // 21
AudioOutputMQS mqs;
CORE_PIN10_CONFIG = prev_pin10_config;
AudioConnection patchCord1 (tonesweep, 0, mixer1, 0);
AudioConnection patchCord4 (mixer1, 0, mqs, 0);
char str[8];
while (1) {
itoa(millis(), str, 10);
displayText(str);
for (int i=0; i < 300; i++) {
do_sweep(tonesweep, mixer1, mqs);
sweep_seconds *= 0.9;
}
sweep_seconds = 3;
}
Serial.println ("Done");
}
void loop (void)
{
}
void do_sweep (AudioSynthToneSweep& tonesweep, AudioMixer4& mixer1, AudioOutputMQS& mqs)
{
float gain = 1.0f;
mixer1.gain (0, gain);
Serial.printf ("Sweep down");
if (!tonesweep.play(0.8, 2000, 200, sweep_seconds)) {
Serial.println("ToneSweep - play failed");
while (1);
}
while (tonesweep.isPlaying ());
Serial.println ("Sweep done");
}
void displayText(const char *text) {
tft.fillScreen(ST77XX_BLACK);
tft.setCursor(0, 0);
tft.setTextColor(ST77XX_WHITE);
tft.setTextWrap(true);
tft.print(text);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment