/***************************************************
This is our GFX example for the Adafruit ILI9341 Breakout and Shield
----> http://www.adafruit.com/products/1651
Check out the links above for our tutorials and wiring diagrams
These displays use SPI to communicate, 4 or 5 pins are required to
interface (RST is optional)
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries.
MIT license, all text above must be included in any redistribution
****************************************************/
#define ST7735_BLACK 0x0000 ///< 0, 0, 0
#define ILI9341_NAVY 0x000F ///< 0, 0, 123
#define ST7735_DARKGREEN 0x03E0 ///< 0, 125, 0
#define ILI9341_DARKCYAN 0x03EF ///< 0, 125, 123
#define ILI9341_MAROON 0x7800 ///< 123, 0, 0
#define ILI9341_PURPLE 0x780F ///< 123, 0, 123
#define ILI9341_OLIVE 0x7BE0 ///< 123, 125, 0
#define ST7735_LIGHTGRAY 0xC618 ///< 198, 195, 198
#define ST7735_GRAY 0x7BEF ///< 123, 125, 123
#define ILI9341_BLUE 0x001F ///< 0, 0, 255
#define ST7735_GREEN 0x07E0 ///< 0, 255, 0
#define ILI9341_CYAN 0x07FF ///< 0, 255, 255
#define ST7735_RED 0xF800 ///< 255, 0, 0
#define ST7735_MAGENTA 0xF81F ///< 255, 0, 255
#define ST7735_YELLOW 0xFFE0 ///< 255, 255, 0
#define ST7735_WHITE 0xFFFF ///< 255, 255, 255
#define ILI9341_ORANGE 0xFD20 ///< 255, 165, 0
#define ILI9341_GREENYELLOW 0xAFE5 ///< 173, 255, 41
#define ILI9341_PINK 0xFC18 ///< 255, 130, 198
#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
// For the Adafruit shield, these are the default.
#define TFT_CLK 52
#define TFT_MISO 50
#define TFT_MOSI 51
#define TFT_DC 8
#define TFT_CS 53
#define TFT_RST 9
// Use hardware SPI (on Uno, #13, #12, #11) and the above for CS/DC
//Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
// If using the breakout, change pins as desired
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);
#define SCREEN_WIDTH 160 // OLED display width, in pixels
#define SCREEN_HEIGHT 128 // OLED display height, in pixels
#define PADDING 40
void setup() {
Serial.begin(9600);
// Serial.println("ILI9341 Test!");
tft.begin();
tft.setRotation(1);
}
void loop() {
tft.setTextColor(ST7735_WHITE);
draw_filter_curves(32, 127, 0, 10,5);
delay(3000);
draw_filter_curves(64, 0, 1, 32, 20);
delay(3000);
draw_filter_curves(127, 64, 2, 64,-40);
delay(3000);
}
// Filter curve ---------------------------------------------------------
const byte FILTERCURVE[385] = {
1, 2, 2, 3, 2, 3, 3, 4,
5, 4, 7, 5, 9, 7, 10, 11,
11, 13, 13, 17, 16, 18, 21, 21,
23, 25, 27, 28, 32, 31, 36, 36,
39, 41, 43, 46, 48, 51, 53, 55,
57, 62, 63, 65, 70, 70, 75, 76,
81, 82, 85, 89, 92, 94, 97, 100,
104, 107, 109, 112, 116, 119, 122, 124,
129, 130, 135, 137, 140, 144, 147, 148,
154, 155, 158, 163, 163, 169, 169, 174,
177, 178, 182, 185, 187, 191, 192, 195,
199, 200, 203, 205, 209, 210, 212, 216,
216, 220, 221, 223, 226, 227, 230, 230,
233, 235, 235, 239, 238, 241, 242, 243,
245, 245, 246, 249, 247, 251, 249, 252,
251, 252, 253, 253, 253, 254, 254, 254,
253, 255, 254, 253, 253, 254, 252, 253,
251, 251, 250, 250, 248, 248, 246, 246,
245, 242, 243, 240, 239, 238, 236, 234,
233, 231, 230, 226, 226, 224, 221, 219,
217, 215, 212, 211, 208, 206, 202, 201,
198, 196, 192, 190, 188, 184, 182, 179,
177, 173, 170, 168, 164, 162, 158, 156,
153, 149, 147, 143, 141, 136, 135, 131,
128, 125, 122, 118, 116, 113, 109, 106,
104, 101, 96, 95, 92, 88, 85, 83,
80, 77, 74, 71, 69, 66, 63, 61,
57, 56, 53, 50, 49, 45, 43, 42,
38, 37, 35, 32, 31, 29, 26, 26,
22, 22, 20, 19, 16, 16, 13, 14,
11, 10, 10, 8, 8, 6, 6, 5,
4, 5, 2, 3, 2, 2, 2, 3,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0,
};
//*************************************************************************
// draw Filter EnvMarker
//*************************************************************************
void drawEnvMarkerVCF(int posx)
{
tft.fillRoundRect(posx, 30, 16, 9, 2, ST7735_GRAY);
// tft.setFont(&Picopixel);
tft.setTextColor(ST7735_WHITE);
tft.setCursor(posx + 2, 36);
tft.print("ENV");
tft.setFont(NULL);
}
//*************************************************************************
// draw Filter EnvMarker
//*************************************************************************
void drawLFOMarkerVCF(int posx)
{
tft.fillRoundRect(posx, 60, 16, 9, 2, ST7735_DARKGREEN);
// tft.setFont(&Picopixel);
tft.setTextColor(ST7735_WHITE);
tft.setCursor(posx + 3, 66);
tft.print("LFO");
tft.setFont(NULL);
}
//*************************************************************************
// draw SVF/Ladder filter curves (0-127)
//*************************************************************************
void draw_filter_curves (int filterCutoff, int filterResonance, int FilterType, int filterLFO, int filterEnv) {
// draw diagramm line
tft.drawLine(19, 39, 19, 86, ST7735_GRAY);
tft.drawLine(19, 86, 134, 86, ST7735_GRAY);
tft.setTextColor(ST7735_GRAY);
tft.setCursor(7, 40);
tft.print("dB");
tft.setCursor(110, 88);
tft.print("f/Hz");
filterCutoff /= 1.36f;
// clear old curve
tft.fillRect(20, 28, 127, 58, ST7735_BLACK);
switch (FilterType) {
// LowPass curve (Red Color) ----------------------------------------
case 0: {
const uint8_t x_plot = 40;
const uint8_t y_plot = 85;
uint8_t x = 40;
uint16_t r = 0;
uint8_t y = 0;
uint8_t y_ = 0;
uint8_t i = 0;
uint8_t i_ = 0;
uint8_t q_typ = 12; // Filter Q
uint16_t resonance = 0;
int xx = 0;
for (i = 0; i < 48; i++) {
resonance = (FILTERCURVE[(i * 8)]);
resonance = (((resonance >> 2) * filterResonance) >> 7);
r = (x + r - y) + resonance;
y = r / q_typ;
xx = filterCutoff + x_plot - i_;
if (xx >= 21) {
tft.drawLine(xx, (y_plot - y_ / 2), filterCutoff + x_plot - i, (y_plot - y / 2), ST7735_RED);
}
i_ = i;
y_ = y;
}
xx = filterCutoff - 5;
if (xx >= 21) {
tft.drawLine(20, (y_plot - y_ / 2), filterCutoff - 5, (y_plot - y_ / 2), ST7735_RED);
}
}
break;
// HighPass curve (Yellow color) ------------------------------------
case 1: {
const int8_t x_plot = -5;
const uint8_t y_plot = 85;
uint8_t x = 40, xx;
uint16_t r = 0;
uint8_t y = 0;
uint8_t y_ = 0;
uint8_t i = 0;
uint8_t i_ = 0;
uint8_t q_typ = 12; // Filter Q
uint16_t resonance = 0;
for (i = 0; i < 48; i++) {
resonance = (FILTERCURVE[(i * 8)]);
resonance = (((resonance >> 2) * filterResonance) >> 7);
r = (x + r - y) + resonance;
y = r / q_typ;
xx = filterCutoff + x_plot + i_;
if (xx >= 21 && xx < 131) {
tft.drawLine(xx, (y_plot - y_ / 2), filterCutoff + x_plot + i, (y_plot - y / 2), ST7735_YELLOW);
}
i_ = i;
y_ = y;
}
xx = 43 + filterCutoff;
if (xx > 21 && xx < 131) {
tft.drawLine(xx, (y_plot - y_ / 2), 131, (y_plot - y_ / 2), ST7735_YELLOW);
}
}
break;
// BandPass curve ---------------------------------------------------
case 2: {
const int8_t x_plot = -5;
const uint8_t y_plot = 85;
uint8_t x = 40;
uint16_t r = 0;
uint8_t y = 0;
uint8_t y_ = 0;
uint8_t i = 0;
uint8_t i_ = 0;
uint8_t q_typ = 12; // Filter Q
uint16_t resonance = 0;
for (i = 0; i < 23; i++)
{
resonance = (FILTERCURVE[(i * 8)]);
resonance = (((resonance >> 2) * filterResonance) >> 7);
r = (x + r - y) + resonance;
y = r / q_typ;
int xx = filterCutoff + x_plot + i_;
if (xx > 19 && xx < 131) {
tft.drawLine(xx, (y_plot - y_ / 2), filterCutoff + x_plot + i, (y_plot - y / 2), ST7735_GREEN);
}
xx = filterCutoff;
if (xx < 1) {
xx = 1;
}
tft.drawLine(xx + x_plot + 46 - i_, (y_plot - y_ / 2), xx + x_plot + 46 - i, (y_plot - y / 2), ST7735_GREEN);
i_ = i;
y_ = y;
}
}
} // endcase
// draw dotline for ENV and LFO ---------------------------------------
int xplot = filterCutoff + 18;
// draw vertikal cutoff dotline
if (xplot > 23) {
for (int i = 42; i < 86; i += 2) {
tft.drawPixel(xplot, i, ST7735_WHITE);
}
}
else {
for (int i = 42; i < 86; i += 2) {
tft.drawPixel(23, i, ST7735_WHITE);
}
}
int vcfamt = filterEnv;
if (xplot > 23) {
if (vcfamt < 0) {
vcfamt = -vcfamt;
for (int i = 0; i < vcfamt; i+=2) {
int plotx = xplot - i;
if (plotx <= 23) {
plotx = 23;
}
// draw left Env arrow line
tft.drawPixel(plotx, 44, ST7735_WHITE);
}
// draw left arrow
int posx = xplot - vcfamt;
if (posx <= 23) {
posx = 23;
}
tft.drawFastVLine(posx, 42, 5, ST7735_WHITE);
tft.drawFastVLine(posx - 1, 43, 3, ST7735_WHITE);
tft.drawPixel(posx - 2, 44, ST7735_WHITE);
posx -= 8;
if (posx <= 25) {
posx = 25;
}
drawEnvMarkerVCF(posx);
}
// draw Env arrow in middle
else if (vcfamt == 0) {
int posx = xplot + vcfamt;
tft.drawFastVLine(posx, 42, 5, ST7735_WHITE);
tft.drawFastVLine(posx + 1, 43, 3, ST7735_WHITE);
tft.drawPixel(posx + 2, 44, ST7735_WHITE);
tft.drawFastVLine(posx, 42, 5, ST7735_WHITE);
tft.drawFastVLine(posx - 1, 43, 3, ST7735_WHITE);
tft.drawPixel(posx - 2, 44, ST7735_WHITE);
posx -= 8;
if (posx <= 25) {
posx = 25;
}
drawEnvMarkerVCF(posx);
}
// draw right Env arrow line
else if (vcfamt > 0) {
for (int i = 0; i < vcfamt; i+=2) {
int posx = xplot + i;
if (posx >= 130) {
posx = 130;
}
tft.drawPixel(posx, 44, ST7735_WHITE);
}
int posx = xplot + vcfamt;
if (posx >= 130) {
posx = 130;
}
tft.drawFastVLine(posx, 42, 5, ST7735_WHITE);
tft.drawFastVLine(posx + 1, 43, 3, ST7735_WHITE);
tft.drawPixel(posx + 2, 44, ST7735_WHITE);
posx = posx - 8;
if (posx <= 25) {
posx = 25;
}
if (posx >= 118) {
posx = 118;
}
drawEnvMarkerVCF(posx);
}
}
else if (xplot > 0 && xplot <= 23 && vcfamt >= 0) {
int posx = 0;
for (int i = 0; i < vcfamt; i+=2) {
posx = 23 + i;
if (posx <= 23) {
posx = 23;
}
tft.drawPixel(posx, 44, ST7735_WHITE);
}
posx = 23 + vcfamt;
if (vcfamt == 0) {
tft.drawFastVLine(posx, 42, 5, ST7735_WHITE);
tft.drawFastVLine(posx + 1, 43, 3, ST7735_WHITE);
tft.drawPixel(posx + 2, 44, ST7735_WHITE);
tft.drawFastVLine(posx, 42, 5, ST7735_WHITE);
tft.drawFastVLine(posx - 1, 43, 3, ST7735_WHITE);
tft.drawPixel(posx - 2, 44, ST7735_WHITE);
}
else if (vcfamt > 0) {
tft.drawFastVLine(posx, 42, 5, ST7735_WHITE);
tft.drawFastVLine(posx + 1, 43, 3, ST7735_WHITE);
tft.drawPixel(posx + 2, 44, ST7735_WHITE);
}
else {
tft.drawFastVLine(posx, 42, 5, ST7735_WHITE);
tft.drawFastVLine(posx - 1, 43, 3, ST7735_WHITE);
tft.drawPixel(posx - 2, 44, ST7735_WHITE);
}
posx = posx - 8;
if (posx <= 25) {
posx = 25;
}
drawEnvMarkerVCF(posx);
}
else if (vcfamt < 0) {
int posx = 23;
tft.drawFastVLine(posx, 42, 5, ST7735_WHITE);
tft.drawFastVLine(posx - 1, 43, 3, ST7735_WHITE);
tft.drawPixel(posx - 2, 44, ST7735_WHITE);
if (posx <= 25) {
posx = 25;
}
drawEnvMarkerVCF(posx);
}
// draw horizontal LFO line
int filterLfoAmt = filterLFO;
filterLFO = filterLFO / 2.3f;
if (xplot > 0) {
int posx = xplot + 7;
drawLFOMarkerVCF(posx);
posx -= 7;
if (posx <= 23) {
posx = 23;
}
if (filterLfoAmt == 0) {
// draw middle LFO arrows
tft.drawFastVLine(posx, 72, 5, ST7735_WHITE);
tft.drawFastVLine(posx + 1, 73, 3, ST7735_WHITE);
tft.drawPixel(posx + 2, 74, ST7735_WHITE);
tft.drawFastVLine(posx, 72, 5, ST7735_WHITE);
tft.drawFastVLine(posx - 1, 73, 3, ST7735_WHITE);
tft.drawPixel(posx - 2, 74, ST7735_WHITE);
}
else {
for (int i = 0; i < filterLFO; i++) {
posx = xplot + i;
if (posx >= 130) {
posx = 130;
}
if (posx <= 23) {
posx = 23;
}
// draw right LFO arrow line
tft.drawPixel(posx, 74, ST7735_WHITE);
posx = xplot - i;
if (posx <= 23) {
posx = 23;
}
// draw left LFO arrow line
tft.drawPixel(posx, 74, ST7735_WHITE);
i++;
}
posx = xplot + filterLFO;
if (posx >= 130) {
posx = 130;
}
if (posx <= 23) {
posx = 23;
}
// draw right LFO arrow
tft.drawFastVLine(posx, 72, 5, ST7735_WHITE);
tft.drawFastVLine(posx + 1, 73, 3, ST7735_WHITE);
tft.drawPixel(posx + 2, 74, ST7735_WHITE);
posx = xplot - filterLFO;
if (posx <= 23) {
posx = 23;
}
// draw left LFO arrow
tft.drawFastVLine(posx, 72, 5, ST7735_WHITE);
tft.drawFastVLine(posx - 1, 73, 3, ST7735_WHITE);
tft.drawPixel(posx - 2, 74, ST7735_WHITE);
}
}
}