// HariChord, 2015
// Playing with OLED Display
// Big thanks to AdaFruit for providing the wonderful libraries!
/*********************************************************************
This is an example for our Monochrome OLEDs based on SSD1306 drivers
Pick one up today in the adafruit shop!
------> http://www.adafruit.com/category/63_98
This example is for a 128x64 size display using SPI to communicate
4 or 5 pins are required to interface
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.
BSD license, check license.txt for more information
All text above, and the splash screen must be included in any redistribution
*********************************************************************/
#define LOGO16_GLCD_HEIGHT 16
#define LOGO16_GLCD_WIDTH 16
static const unsigned char PROGMEM logo16_glcd_bmp[] =
{
B00000000, B11000000,
B00000001, B11000000,
B00000001, B11000000,
B00000011, B11100000,
B11110011, B11100000,
B11111110, B11111000,
B01111110, B11111111,
B00110011, B10011111,
B00011111, B11111100,
B00001101, B01110000,
B00011011, B10100000,
B00111111, B11100000,
B00111111, B11110000,
B01111100, B11110000,
B01110000, B01110000,
B00000000, B00110000
};
#include <SPIN.h>
#include <SPI.h>
#include "ILI9341_t3n.h"
#include "ili9341_t3n_font_ArialBold.h"
uint8_t use_dma = 0;
uint8_t use_fb = 0;
#define TFT_CS 10
#define TFT_DC 15
//#define RST 15 // reset pin / to 3.3v
ILI9341_t3n tft = ILI9341_t3n(TFT_CS, TFT_DC); // RST connected to 3.3v
elapsedMillis since_Update;
// uint8_t BackLight = 8; // TFT PWM BackLight
// uint8_t Debug_led = 6;
float TIMER;
float TIMER2;
int nFrames = 250;
void setup() {
// start demo
// ---- Configuration for the demo ----
use_fb = 1; // 1 = Force frame buffer on
use_dma = 0; // 1 = Force DMA on
// ---- Configuration for the demo ----
//Serial.begin(115200);
tft.begin();
tft.setRotation(3); // TFT Rotation 0~3
tft.useFrameBuffer(use_fb); // frame buffer on
// tft.updateScreenDMA(true); // continuous update
// Clear the display.
tft.fillScreen(ILI9341_BLACK);
// Show Adafruit splashscreen image on the display hardware.
tft.drawBitmap(160, 120, logo16_glcd_bmp, 16, 16, ILI9341_WHITE);
tft.updateScreenDMA(); // Update Once DMA
delay(1000);
tft.setFont(Arial_9_Bold);
tft.setTextColor(ILI9341_WHITE);
tft.updateScreenDMA(); // Update Once DMA
delay(2000);
// Clear the display.
tft.fillScreen(ILI9341_BLACK);
delay(200);
since_Update = 0; // elapsedMillis
}
void loop() {
for (int frame = 0; frame < nFrames; frame++)
{
HariChord(frame);
if (frame == nFrames - 1) {
TIMER2 = TIMER / 10;
TIMER = 0;
}
}
for (int frame = (nFrames ); frame >= 0; frame--)
{
HariChord(frame);
if (frame == 0) {
TIMER2 = TIMER / 10;
TIMER = 0;
}
}
}
void HariChord(int frame)
{
tft.fillScreen(ILI9341_BLACK);
int n = 9;
int r = frame * 125 / nFrames;
float rot = frame * 2 * PI / nFrames;
for (int i = 0; i < (n ); i++)
{
float a = rot + i * 2 * PI / n;
int x1 = 160 + cosf(a) * r; // tft x 320 / 2
int y1 = 120 + sinf(a) * r; // tft y 240 / 2
for (int j = i + 1; j < n; j++)
{
a = rot + j * 2 * PI / n;
int x2 = 160 + cosf(a) * r;
int y2 = 120 + sinf(a) * r;
tft.drawLine(x1, y1, x2, y2, ILI9341_GREEN);
}
}
tft.setTextColor(ILI9341_WHITE);
tft.setCursor(2, 2);
tft.print("F_CPU ");
tft.setTextColor(ILI9341_CYAN);
tft.print(F_CPU);
tft.setTextColor(ILI9341_WHITE);
tft.print(" MHZ");
tft.setTextColor(ILI9341_WHITE);
tft.setCursor(2, 17);
tft.print("F_BUS ");
tft.setTextColor(ILI9341_CYAN);
tft.print(F_BUS); // F_BUS
tft.setTextColor(ILI9341_WHITE);
tft.print(" MHZ");
tft.setCursor(2, 32);
tft.setTextColor(ILI9341_WHITE);
tft.print("SPI ");
tft.setTextColor(ILI9341_CYAN);
tft.print(F_BUS / 2); // F_BUS
tft.setTextColor(ILI9341_WHITE);
tft.print(" MHZ");
tft.setCursor(2, 228);
tft.setTextColor(ILI9341_WHITE);
tft.print("ILI9341_SPICLOCK SPI set to MAX");
tft.setCursor(230, 228);
tft.setTextColor(ILI9341_CYAN);
tft.print(ILI9341_SPICLOCK); // F_BUS
tft.setTextColor(ILI9341_WHITE);
tft.print(" MHZ");
tft.setCursor(2, 46);
tft.print("frame ");
tft.setTextColor(ILI9341_CYAN);
tft.print(frame); //
if (since_Update > 100) {
since_Update = 0;
TIMER = TIMER + 1;
}
tft.setCursor(2, 61);
tft.print("TIMER ");
tft.print(TIMER);
tft.setCursor(2, 77);
tft.print(nFrames);
tft.setTextColor(ILI9341_RED);
tft.print(" FP ");
tft.print(TIMER2);
tft.print(" Sec");
if ((use_fb == 1) && (use_dma == 1)) {
tft.updateScreenDMA(); // Update Once DMA, Buffer ON
delay(45); // (23) F_BUS @ 120000000MHZ 60MHZ SPI
// (30) F_BUS @ 90000000MHZ 45MHZ SPI
// (45) F_BUS @ 60000000MHZ 30MHZ SPI
}
if ((use_fb == 1) && (use_dma == 0)) {
tft.updateScreen(); // Update Once No DMA, Buffer ON
}
}