When will ESP32-S2 add to Arduino?
Posted: Thu May 14, 2020 12:26 am
Code: Select all
//mandelbrot06.ino
// http://rosettacode.org/wiki/Mandelbrot_set
// https://www.khanacademy.org/computer-programming/mandelbrot-set/1054272371
// https://github.com/cslarsen/mandelbrot-js
// http://falcosoft.hu/html5_mandelbrot.html
//
long startTime = 0;
#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
// For the Adafruit shield, these are the default.
#define HSPI_MISO 12
#define HSPI_MOSI 13
#define HSPI_SCLK 14
#define HSPI_SS 15
#if CONFIG_IDF_TARGET_ESP32S2
#define HSPI FSPI
#endif
#define TFT_DC 4
#define TFT_RST 5
SPIClass * hspi = new SPIClass(HSPI);
Adafruit_ILI9341 tft = Adafruit_ILI9341(hspi, TFT_DC, HSPI_SS, TFT_RST);
void setup() {
Serial.begin(115200);
hspi->begin(HSPI_SCLK, HSPI_MISO, HSPI_MOSI, HSPI_SS);
tft.begin(80000000);
tft.setRotation(3);
tft.fillScreen(ILI9341_BLACK);
xTaskCreate(task1, "t1", 4*1024, NULL, 5, NULL); // in first part priority 5
xTaskCreate(task2, "t2", 4*1024, NULL, 5, NULL); // in first part priority 4
xTaskCreate(task3, "t3", 4*1024, NULL, 5, NULL); // in first part priority 3
xTaskCreate(task4, "t4", 4*1024, NULL, 5, NULL); // in first part priority 2
}
void task1(void*p)
{
while(1)
{
tft.fillRect(0, 0, 160, 120, ILI9341_PINK);
myMandel(-2.000, 1.000, -1.000, 1.000, 99, 120, 160, 0, 0);
delay(3000);
}
}
void task2(void*p)
{
while(1)
{
tft.fillRect(0, 120, 160, 120, ILI9341_RED);
myMandel(-2.0262812499999998, -1.7157656249999997, 0.1242708333333333, -0.1088020833333334, 99, 240, 160, 120, 0);
delay(3000);
}
}
void task3(void*p)
{
while(1)
{
tft.fillRect(160, 0, 160, 120, ILI9341_GREEN);
myMandel(0.3086785098726753, 0.5163214901273253, -0.2804711524861787, -0.4345288475138219, 150, 120, 320, 0, 160);
delay(3000);
}
}
void task4(void*p)
{
while(1)
{
tft.fillRect(160, 120, 160, 120, ILI9341_BLUE);
myMandel(0.4329398558688174, 0.4498108480145078, -0.3687333735957660, -0.3812505613167620, 200, 240, 320, 120, 160);
delay(3000);
}
}
void loop() {
delay(1000000);
}
void myMandel(double realMin, double realMax, double imagMin, double imagMax, int maxIterations, double ySize, double xSize, int y0, int x0) {
// http://rosettacode.org/wiki/Mandelbrot_set#AWK
startTime = millis();
String myString = "\n\nrealMin=" + String(realMin) + ", realMax=" + String(realMax) + ", imagMin=" + String(imagMin) + ", imagMax=" + String(imagMax) + ", maxIterations=" + String(maxIterations) + ", startTime=" + String((startTime / 1000.0)) + "s";
Serial.print(myString);
//================================================================
double xStep = (realMax - realMin) / xSize;
double yStep = (imagMax - imagMin) / ySize;
int color = 0;
for (int y = y0; y < ySize; y++) {
double imagY = imagMin + yStep * y;
for (int x = x0; x < xSize; x++) {
double realX = realMin + xStep * x;
double realZ = realX;
double imagZ = imagY;
for (int n = 0; n <= maxIterations; n++) {
color = n;
double a = realZ * realZ;
double b = imagZ * imagZ;
if (a + b > 4.0) break;
imagZ = 2 * realZ * imagZ + imagY;
realZ = a - b + realX;
}
if(color != maxIterations )
tft.drawPixel(x, y, color*128*64);
}
delay(1);
}
//================================================================
long elapseTime = millis() - startTime;
myString = "\nelapseTime=" + String((elapseTime / 1000.0)) + "s";
Serial.print(myString);
}
Using Arduino IDE with the development repository