/**
First demo for FT6206 Capactive Touch Screen on Wokwi. Enjoy!
https://wokwi.com/arduino/projects/311598148845830720
*/
/***************************************************
This is our touchscreen painting example for the Adafruit ILI9341
captouch shield
----> http://www.adafruit.com/products/1947
Check out the links above for our tutorials and wiring diagrams
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
****************************************************/
#include <Adafruit_GFX.h> // Core graphics library
#include <SPI.h> // this is needed for display
#include <Adafruit_ILI9341.h>
#include <Wire.h> // this is needed for FT6206
#include <Adafruit_FT6206.h>
// The FT6206 uses hardware I2C (SCL/SDA)
Adafruit_FT6206 ctp = Adafruit_FT6206();
// The display also uses hardware SPI, plus #9 & #10
#define TFT_CS 10
#define TFT_DC 9
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
// Size of the color selection boxes and the paintbrush size
#define BOXSIZE 40
#define PENRADIUS 3
int oldcolor, currentcolor;
float x=0, phi=200, speed=0.2,y=0, xscale=1.5;
int x0=20,i=0, offset=120, xres=320, yres=240;
int reset=int(xres*xscale), active_on=LOW;
float z=x-phi ;
float *p;
volatile int state = HIGH;
void setup(void) {
/*pinMode(10, INPUT_PULLUP);
pinMode(11, INPUT_PULLUP);
pinMode(12, INPUT_PULLUP);
pinMode(13, INPUT_PULLUP);
*/
pinMode(2, INPUT_PULLUP);
pinMode(A5, INPUT_PULLUP);
// Enable Pin Change Interrupt on PCINT11 (A3)
PCMSK2 |= (1 << PCINT13);
// Enable Pin Change Interrupt for PCINT[23:16]
PCICR |= (1 << PCIE2);
// Attach the ISR (Interrupt Service Routine)
sei(); // Enable global interrupts
//*p=5;
while (!Serial); // used for leonardo debugging
Serial.begin(115200);
Serial.println(F("Cap Touch Paint!"));
tft.begin();
Serial.println("Capacitive touchscreen started");
tft.fillScreen(ILI9341_BLACK);
}
float rndFloat(float min, float max) {
return ((float)rand() / RAND_MAX) * (max - min) + min;
}
float sinrhythm(float x){
return 0.005*(20*exp(-pow(((x-x0)/16),2))-30*exp(-pow(((x-x0-75)/5),2))+200*exp(-pow(((x-x0-93)/11.2),2))+60*exp(-pow(((x-x0-193)/29),2))+10*exp(-pow(((x-x0-260)/10),2))+-50*exp(-pow(((x-x0-111)/5),2)));
}
float vtachycard(float x){
return 250*exp(-pow(((x-50)/20),2))+70*exp(-pow(((x-25)/10),2))-200*exp(-pow(((x-120)/20),2))+50*exp(-pow(((x-119)/5),2));
}
float vfib(float x, float d){
return 0.5*sin(x/5)+0.1*sin(d*x/10)+0.01*d*sin(x);
}
float asys(float x, float d){
return 0.05*sin(d + x/100)+ d/100*sin(x/d/10);
}
float(*fnptr)(float,float);
void loop() {
//Serial.println(digitalRead(2));
// function ptr waiting for function select
if((x==reset) || x ==0){y=rndFloat(1,5);};
fnptr=asys;
// first in draw is y then x
x=(x+speed)-(int(x)/reset)*reset;
tft.drawPixel(-50*fnptr(x,y)+offset,xres- (x/xscale),ILI9341_WHITE);
if(x>reset-2){
while(z<reset){
tft.fillRect(-50*fnptr(z,y)+offset-4,xres-4-(z/xscale), 10, 10, ILI9341_BLACK);
z=(z+speed*5)-(int(z)/reset)*reset;
x= reset;
}
z=(z+speed*5)-(int(z)/reset)*reset;
}
}
ISR(PCINT2_vect) {
int currentState = digitalRead(A5);
// Check if the state has changed
if (currentState != state) {
state = currentState;
// Your code to handle the pin change
if(currentState == LOW){Serial.println("BOOP");}
}
}