char* modes={“INPUT”, “PLAY”, “RECORD”, “CUT”, “COPY”, “CUT>”, “CUTALL”, “SMOVE”, “SCOPY”, “RESET”,“10”,“KEY”,“12”,“SAVE”,“LOAD”,“15”,“16”,“17”,“18”,“19”};
char* disp ={“u”, “d”, “l”, “r”, “a”, “b”, “x”, “y”, “c”, “z”, “p”, “q”, “h”, “s”, “e”, " ",};
#include “SD.h”
#include “SPI.h”
#include “Adafruit_GFX.h”
#include “Adafruit_ILI9341.h”
#include “Wire.h” // this is needed for FT6206
#include “Adafruit_FT6206.h”
// For the Adafruit shield, these are the default.
#define TFT_DC 9
#define TFT_CS 10
#define SD_CS 4
char* myTXTs={“log0.txt”, “log1.txt”, “log2.txt”, “log3.txt”, “log4.txt”};
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
Adafruit_FT6206 ctp = Adafruit_FT6206();
//u d r l se ho st sq tr r1 l1 gnd x o r2 l2
//u d r l se ho st sq tr r1 l1 gnd x o r2 l2
int p1 = {37,36,34,35,30,29,25,24, 0,15,30,45,60,75,90,105,
0,0,0,0,0,0,0,0, 0,1,2,3,4,5,6,7};
int p2 = {49,48,46,47,44,45,41,40, 0,15,30,45,60,75,90,105,
16,16,16,16,16,16,16,16, 0,1,2,3,4,5,6,7};
int p3 = {28,23,27,22,32,31,33,33, 120,135,150,165,180,195,210,225,
0,0,0,0,0,0,0,0, 8,9,10,11,12,13,14,15};
int p4 = {42,39,43,38,63,64,65,66, 120,135,150,165,180,195,210,225,
16,16,16,16,16,16,16,16, 8,9,10,11,12,13,14,15};
int cs_pin=53;int tempread;
int held=0;
int invert_controls=0;
int P1=1; int P2=1; int P3=1; int P4=1;
int button=0; int last_button;
byte record[5][1200];
int selection_start=0; int selection_width;
int selection_end=4; int loop_number=0; int repetition=0;
unsigned long time1; unsigned long time2; unsigned long time3;
unsigned long time4; unsigned long time5;
int lag=0;
int mode = -1;
int current_slot = 0; int cursor_position = 0;
int pressed=0; int unpressed=1; int all_unpressed=255;int all_pressed=0;
int F=16656; int frame_count=0;
int n;int i;
int wait_input=0;
void dispP1(){for(n=0;n<8;n++){
tft.fillRect (p1[n+8],p1[n+16],15,16,ILI9341_BLUE);
if(bitRead(record[1][current_slot],n)==pressed)
{tft.setCursor(p1[n+8],p1[n+16]);tft.print(disp[p1[n+24]]);}
tft.fillRect (p2[n+8],p2[n+16],15,16,ILI9341_BLUE);
if(bitRead(record[2][current_slot],n)==pressed)
{tft.setCursor(p2[n+8],p2[n+16]);tft.print(disp[p2[n+24]]);}
tft.fillRect (p3[n+8],p3[n+16],15,16,ILI9341_BLUE);
if(bitRead(record[3][current_slot],n)==pressed)
{tft.setCursor(p3[n+8],p3[n+16]);tft.print(disp[p3[n+24]]);}
tft.fillRect (p4[n+8],p4[n+16],15,16,ILI9341_BLUE);
if(bitRead(record[4][current_slot],n)==pressed)
{tft.setCursor(p4[n+8],p4[n+16]);tft.print(disp[p4[n+24]]);}
}}
void saveSD (int x, int y) {
SD.remove(myTXTs);
File datafile = SD.open(myTXTs,FILE_WRITE);
if(datafile){
for(i=0;i<1200;i++){for(n=0;n<8;n++){
datafile.print(bitRead(record[y][i],n));}}//datafile.println();
datafile.close();}}
void loadSD (int x, int y)
{File readfile = SD.open(myTXTs);
if (readfile){while(readfile.available())
{for(i=0;i<1200;i++){
for (n=0;n<8;n++){
tempread=readfile.read();
if(tempread==‘0’){bitWrite(record[y][i],n,0);}
if(tempread==‘1’){bitWrite(record[y][i],n,1);}
}}}}
readfile.close();}
void setup() {
pinMode(cs_pin,OUTPUT);
tft.begin();
ctp.begin();
tft.setTextColor(ILI9341_WHITE); tft.setTextSize(2);
tft.setRotation(2);
tft.fillScreen(ILI9341_BLUE);
tft.drawRect(0,240,80,80,ILI9341_RED);
tft.drawRect(80,240,80,80,ILI9341_RED);
tft.drawRect(160,240,80,80,ILI9341_RED);
tft.drawRect(0,160,80,80,ILI9341_RED);
tft.drawRect(80,160,80,80,ILI9341_RED);
tft.drawRect(160,160,80,80,ILI9341_RED);
//pinMode(cs_pin,OUTPUT);
for(n=0;n<8;n++)
{pinMode(p1[n],OUTPUT);pinMode(p2[n],OUTPUT);
pinMode(p3[n],OUTPUT);pinMode(p4[n],OUTPUT);
digitalWrite(p1[n],unpressed);digitalWrite(p2[n],unpressed);
digitalWrite(p3[n],unpressed);digitalWrite(p4[n],unpressed);}
for(n=0;n<1200;n++){record[0][n]=all_unpressed;
record[1][n]=all_unpressed;
record[2][n]=all_unpressed;
record[3][n]=all_unpressed;
record[4][n]=all_unpressed;}
tft.setCursor(1,161);tft.fillRect(1,161,78,30,ILI9341_BLUE);
tft.print(current_slot);
tft.setCursor(81,161);tft.fillRect (81,161,78,30,ILI9341_BLUE);
tft.print(modes[cursor_position]);
if(P1==1){tft.setCursor(170,170);tft.print(“P1”);}
if(P3==1){tft.setCursor(210,170);tft.print(“P3”);}
if(P2==1){tft.setCursor(170,210);tft.print(“P2”);}
if(P4==1){tft.setCursor(210,210);tft.print(“P4”);}
tft.setCursor(61,81);tft.print(selection_start);
tft.setCursor(121,81);tft.print(selection_end);
tft.setCursor(181,81);tft.print(loop_number);
if (!SD.begin(SD_CS)) {
tft.setCursor(0,220);tft.print(“SDF”);
}
tft.setCursor(0,220);tft.print(“SD”);
}
void loop() {
time2=micros();
if((time2)>(time1+F)) {
time1=micros();
selection_width=selection_end-selection_start;
if(mode==1) {time4=micros();
for(n=0;n<8;n++){
if(P1==1){digitalWrite(p1[n],(bitRead(record[1][frame_count],n)));}
if(P3==1){digitalWrite(p3[n],(bitRead(record[3][frame_count],n)));}
if(P2==1){digitalWrite(p2[n],(bitRead(record[2][frame_count],n)));}
if(P4==1){digitalWrite(p4[n],(bitRead(record[4][frame_count],n)));}}
if((frame_count==selection_end) && (repetition>0))
{repetition–;frame_count=selection_start-1;}
if(frame_count>1199){for(n=0;n<8;n++)
{digitalWrite(p1[n],unpressed); digitalWrite(p2[n],unpressed);
digitalWrite(p3[n],unpressed); digitalWrite(p4[n],unpressed);}
time3=micros();time5=time3-time4;mode=-1;}
}
if(mode==2) {for(n=0;n<8;n++){
if(P1==1){bitWrite(record[1][frame_count],n,digitalRead(p1[n]));}
if(P3==1){bitWrite(record[3][frame_count],n,digitalRead(p3[n]));}
if(P2==1){bitWrite(record[2][frame_count],n,digitalRead(p2[n]));}
if(P4==1){bitWrite(record[4][frame_count],n,digitalRead(p4[n]));}}
if(frame_count==0){
if ( ((P1==1)&&(record[1][0]!=all_unpressed)) or
((P2==1)&&(record[3][0]!=all_unpressed)) or
((P3==1)&&(record[2][0]!=all_unpressed)) or
((P4==1)&&(record[4][0]!=all_unpressed)) )
{} else {frame_count=-1;}}
if(frame_count>1199){mode=-1;}
}
if(mode==0){
for(n=0;n<8;n++){
if(P1==1){bitWrite(record[1][current_slot],n,digitalRead(p1[n]));}
if(P3==1){bitWrite(record[3][current_slot],n,digitalRead(p3[n]));}
if(P2==1){bitWrite(record[2][current_slot],n,digitalRead(p2[n]));}
if(P4==1){bitWrite(record[4][current_slot],n,digitalRead(p4[n]));}}
dispP1();
current_slot++;delay(300);
tft.setCursor(1,161);tft.fillRect(1,161,78,30,ILI9341_BLUE);
tft.print(current_slot);
dispP1();
mode=-1;}
if (ctp.touched()) {
TS_Point p = ctp.getPoint(); // x = 240, y= 320
if(p.x<80 && p.y>240){button=4;}
if(160>p.x && p.x>80 && p.y>240){button=2;}
if(240>p.x && p.x>160 && p.y>240){button=6;}
if(p.x<80 && p.y>160 && p.y<240){button=5;}
if(160>p.x && p.x>80 && p.y>160 && p.y<240){button=8;}
if(p.x>160 && p.x<200 && p.y>160 && p.y<200){button=7;}
if(p.x>200 && p.y>160 && p.y<200){button=9;}
if(p.x>160 && p.x<200 && p.y>200 && p.y<240){button=1;}
if(p.x>200 && p.y>200 && p.y<240){button=3;}
if(p.x<60 && p.y>80 && p.y<160){button=10;}
if(120>p.x && p.x>60 && p.y>80 && p.y<160){button=11;}
if(180>p.x && p.x>120 && p.y>80 && p.y<160){button=12;}
if(240>p.x && p.x>180 && p.y>80 && p.y<160){button=13;}
if(p.x<60 && p.y>0 && p.y<80){button=14;}
if(120>p.x && p.x>60 && p.y>0 && p.y<80){button=15;}
if(180>p.x && p.x>120 && p.y>0 && p.y<80){button=16;}
if(240>p.x && p.x>180 && p.y>0 && p.y<80){button=17;}
}
else
{button=0;held=0;}
if (button==7 && last_button==0)
{P1=abs(P1-1);P3=P1;
tft.fillRect (170,170,69,29,ILI9341_BLUE);
if(P1==1){tft.setCursor(170,170);tft.print(“P1”);}
if(P3==1){tft.setCursor(210,170);tft.print(“P3”);}}
if (button==1 && last_button==0)
{P2=abs(P2-1);P4=P2;
tft.fillRect (170,210,69,29,ILI9341_BLUE);
if(P2==1){tft.setCursor(170,210);tft.print(“P2”);}
if(P4==1){tft.setCursor(210,210);tft.print(“P4”);}}
if (button==9 && last_button==0)
{P3=abs(P3-1);
tft.fillRect (210,170,29,29,ILI9341_BLUE);
if(P3==1){tft.setCursor(210,170);tft.print(“P3”);}}
if (button==3 && last_button==0)
{P4=abs(P4-1);
tft.fillRect (210,210,29,29,ILI9341_BLUE);
if(P4==1){tft.setCursor(210,210);tft.print(“P4”);}}
if (button==4){
mode=-1;for(n=0;n<8;n++)
{digitalWrite(p1[n],unpressed); digitalWrite(p2[n],unpressed);
digitalWrite(p3[n],unpressed); digitalWrite(p4[n],unpressed);}
if ((cursor_position>0) && (last_button==0)){cursor_position–;}
tft.setCursor(81,161);tft.fillRect (81,161,78,30,ILI9341_BLUE);
tft.print(modes[cursor_position]);}
if (button==6){
mode=-1;
for(n=0;n<8;n++)
{digitalWrite(p1[n],unpressed); digitalWrite(p2[n],unpressed);
digitalWrite(p3[n],unpressed); digitalWrite(p4[n],unpressed);}
if((cursor_position <19) && (last_button==0)){cursor_position++;}
tft.setCursor(81,161);tft.fillRect (81,161,78,30,ILI9341_BLUE);
tft.print(modes[cursor_position]);
}
if(button==8){
if((cursor_position==8) && (last_button==0) && ((selection_end+selection_width)<1199))
{for(n=0;n<(selection_width+1);n++)
{if(P1==1){record[1][selection_end+n+1]=record[1][selection_start+n];}
if(P2==1){record[2][selection_end+n+1]=record[2][selection_start+n];}
if(P3==1){record[3][selection_end+n+1]=record[3][selection_start+n];}
if(P4==1){record[4][selection_end+n+1]=record[4][selection_start+n];}
}
selection_start=selection_end+1;
selection_end=selection_end + selection_width+1;
if(current_slot+selection_width<1199){current_slot=current_slot+selection_width+1;}
dispP1();
tft.setCursor(61,81);
tft.fillRect(61,81,40,30,ILI9341_BLUE);tft.print(selection_start);
tft.setCursor(121,81);
tft.fillRect(121,81,40,30,ILI9341_BLUE);tft.print(selection_end);
}
if((cursor_position==7) && (last_button==0) && (selection_end<1199))
{for(n=selection_end;n>selection_start-1;n--)
{if(P1==1){record[1][n+1]=record[1][n];}
if(P2==1){record[2][n+1]=record[2][n];}
if(P3==1){record[3][n+1]=record[3][n];}
if(P4==1){record[4][n+1]=record[4][n];}
}
if(P1==1){record[1][selection_start]=all_unpressed;}
if(P2==1){record[2][selection_start]=all_unpressed;}
if(P3==1){record[3][selection_start]=all_unpressed;}
if(P4==1){record[4][selection_start]=all_unpressed;}
selection_start++;selection_end++;
if(current_slot<1199){current_slot++;}dispP1();
tft.setCursor(61,81);
tft.fillRect(61,81,40,30,ILI9341_BLUE);tft.print(selection_start);
tft.setCursor(121,81);
tft.fillRect(121,81,40,30,ILI9341_BLUE);tft.print(selection_end);
}
if((cursor_position==0) && (last_button==0) && (current_slot<1199))
{current_slot++;mode=-1;
dispP1();}
if((cursor_position==1) && (current_slot<1199)){
delay(25); current_slot++;mode=-1;
dispP1();
}
if((cursor_position==2) && (current_slot<1199)){
delay(5);
current_slot++;mode=-1;
// dispP1();
}
if((cursor_position==3) && (last_button==0) && (current_slot<1199)){
if(P1==1) {record[1][current_slot+1]=record[1][current_slot];
record[1][current_slot]=all_unpressed;
record[3][current_slot+1]=record[3][current_slot];
record[3][current_slot]=all_unpressed;}
if(P2==1) {record[2][current_slot+1]=record[2][current_slot];
record[2][current_slot]=all_unpressed;
record[4][current_slot+1]=record[4][current_slot];
record[4][current_slot]=all_unpressed;}
current_slot++;mode=-1;
dispP1();}
if((cursor_position==4) && (last_button==0) && (current_slot<1199)){
if(P1==1) {record[1][current_slot+1]=record[1][current_slot];
record[3][current_slot+1]=record[3][current_slot];}
if(P2==1) {record[2][current_slot+1]=record[2][current_slot];
record[4][current_slot+1]=record[4][current_slot];}
current_slot++;mode=-1;
dispP1(); }
if((cursor_position==5) && (last_button==0) && (current_slot<1199)){
if(P1==1){for(n=1198;n>(current_slot-1);n–)
{record[1][n+1]=record[1][n];record[3][n+1]=record[3][n];}
record[1][current_slot]=all_unpressed;
record[3][current_slot]=all_unpressed;}
if(P2==1){for(n=1198;n>(current_slot-1);n–)
{record[2][n+1]=record[2][n];record[4][n+1]=record[4][n];}
record[2][current_slot]=all_unpressed;
record[4][current_slot]=all_unpressed;}
current_slot++;mode=-1;
dispP1();}
if((cursor_position==6) && (last_button==0)){
if(P1==1){for(n=1198;n>-1;n–)
{record[1][n+1]=record[1][n];record[3][n+1]=record[3][n];}
record[1][0]=all_unpressed;record[3][0]=all_unpressed;}
if(P2==1){for(n=1198;n>-1;n–)
{record[2][n+1]=record[2][n];record[4][n+1]=record[4][n];}
record[2][0]=all_unpressed;record[4][0]=all_unpressed;}
current_slot++;mode=-1;
dispP1();}
if(cursor_position==16){F++;}
if(cursor_position==9){
unpressed=1;pressed=0;all_unpressed=255;
for(n=0;n<8;n++){
digitalWrite(p1[n],unpressed); digitalWrite(p2[n],unpressed);
digitalWrite(p3[n],unpressed); digitalWrite(p4[n],unpressed);}
for(n=0;n<1200;n++){record[1][n]=all_unpressed;
record[2][n]=all_unpressed;
record[3][n]=all_unpressed;
record[4][n]=all_unpressed;}}
}
if ((button==2)){
if((cursor_position==8) && (last_button==0) && ((selection_start-selection_width)>0))
{for(n=0;n<(selection_width+1);n++)
{if(P1==1){record[1][selection_start-n-1]=record[1][selection_end-n];}
if(P2==1){record[2][selection_start-n-1]=record[2][selection_end-n];}
if(P3==1){record[3][selection_start-n-1]=record[3][selection_end-n];}
if(P4==1){record[4][selection_start-n-1]=record[4][selection_end-n];}
}
selection_end=selection_start-1;
selection_start=selection_start - selection_width-1;
if(current_slot-selection_width>0){current_slot=current_slot-selection_width-1;}
dispP1();
tft.setCursor(61,81);
tft.fillRect(61,81,40,30,ILI9341_BLUE);tft.print(selection_start);
tft.setCursor(121,81);
tft.fillRect(121,81,40,30,ILI9341_BLUE);tft.print(selection_end);
}
if((cursor_position==7) && (last_button==0) && (selection_start>0))
{for(n=selection_start;n<selection_end+1;n++)
{if(P1==1){record[1][n-1]=record[1][n];}
if(P2==1){record[2][n-1]=record[2][n];}
if(P3==1){record[3][n-1]=record[3][n];}
if(P4==1){record[4][n-1]=record[4][n];}
}
if(P1==1){record[1][selection_end]=all_unpressed;}
if(P2==1){record[2][selection_end]=all_unpressed;}
if(P3==1){record[3][selection_end]=all_unpressed;}
if(P4==1){record[4][selection_end]=all_unpressed;}
selection_start--;selection_end--;
if(current_slot>0){current_slot--;}dispP1();
tft.setCursor(61,81);
tft.fillRect(61,81,40,30,ILI9341_BLUE);tft.print(selection_start);
tft.setCursor(121,81);
tft.fillRect(121,81,40,30,ILI9341_BLUE);tft.print(selection_end);
}
if ((cursor_position==0) && (last_button==0) && (current_slot>0)){
current_slot--;mode=-1;
dispP1();}
if ((cursor_position==1) && (current_slot>0)){
delay(25); current_slot--;mode=-1;
dispP1();}
if ((cursor_position==2) && (current_slot>0)){
delay(5); current_slot--;mode=-1;
//dispP1();
}
if ((cursor_position==3) && (current_slot>0) && (last_button==0)){
if(P1==1) {record[1][current_slot-1]=record[1][current_slot];
record[1][current_slot]=all_unpressed;
record[3][current_slot-1]=record[3][current_slot];
record[3][current_slot]=all_unpressed;}
if(P2==1) {record[2][current_slot-1]=record[2][current_slot];
record[2][current_slot]=all_unpressed;
record[4][current_slot-1]=record[4][current_slot];
record[4][current_slot]=all_unpressed;}
current_slot--;mode=-1;
dispP1();}
if ((cursor_position==4) && (current_slot>0) && (last_button==0)){
if (P1==1) {record[1][current_slot-1]=record[1][current_slot];
record[3][current_slot-1]=record[3][current_slot];}
if (P2==1) {record[2][current_slot-1]=record[2][current_slot];
record[4][current_slot-1]=record[4][current_slot];}
current_slot--;mode=-1;
dispP1();}
if ((cursor_position==5) && (current_slot>0) && (last_button==0)){
if (P1==1) {for(n=current_slot;n<1199;n++)
{record[1][n-1]=record[1][n];record[3][n-1]=record[3][n];}
record[1][1199]=all_unpressed;record[3][1199]=all_unpressed;}
if (P2==1) {for(n=current_slot;n<1199;n++)
{record[2][n-1]=record[2][n];record[4][n-1]=record[4][n];}
record[2][1199]=all_unpressed;record[4][1199]=all_unpressed;}
current_slot–;mode=-1;
dispP1();
}
if((cursor_position==6)&& (current_slot>0) && (last_button==0)){
if (P1==1) {for(n=1;n<1199;n++){record[1][n-1]=record[1][n];
record[3][n-1]=record[3][n];}
record[1][1199]=all_unpressed;record[3][1199]=all_unpressed;}
if (P2==1) {for(n=1;n<1199;n++){record[2][n-1]=record[2][n];
record[4][n-1]=record[4][n];}
record[2][1199]=all_unpressed;record[4][1199]=all_unpressed;}
current_slot--;mode=-1;
dispP1(); }
if(cursor_position==16){F–;}
if(cursor_position==9){
unpressed=0;pressed=1;all_unpressed=0;
for(n=0;n<8;n++){
digitalWrite(p1[n],unpressed); digitalWrite(p2[n],unpressed);
digitalWrite(p3[n],unpressed); digitalWrite(p4[n],unpressed);}
for(n=0;n<1200;n++){record[1][n]=all_unpressed;
record[2][n]=all_unpressed;
record[3][n]=all_unpressed;
record[4][n]=all_unpressed;}}
}
if(button==5){
if((cursor_position==13) && (last_button==0))
{
saveSD(1,1);
saveSD(2,2);
saveSD(3,3);
saveSD(4,4);
}
if((cursor_position==14) && (last_button==0))
{
loadSD(1,1);
loadSD(2,2);
loadSD(3,3);
loadSD(4,4);
}
if((cursor_position==0) && (last_button==0))
{mode=0;}
if((cursor_position==1) && (last_button==0))
{repetition=0;frame_count=-1;mode=1;repetition=loop_number;}
if((cursor_position==2) && (last_button==0)){
for(n=0;n<1200;n++){
if(P1==1){record[1][n]=all_unpressed;}
if(P2==1){record[2][n]=all_unpressed;}
if(P3==1){record[3][n]=all_unpressed;}
if(P4==1){record[4][n]=all_unpressed;}}
frame_count=-1;mode=2;}
if((cursor_position==3) && (last_button==0))
{frame_count=-1;mode=1;}
if((cursor_position==4) && (last_button==0))
{frame_count=-1;mode=1;}
if((cursor_position==5) && (last_button==0))
{frame_count=-1;mode=1;}
if((cursor_position==6) && (last_button==0))
{frame_count=-1;mode=1;}
if(cursor_position==9)
{if(P1==1){for(n=0;n<1200;n++){record[1][n]=all_unpressed;}}
if(P2==1){for(n=0;n<1200;n++){record[2][n]=all_unpressed;}}
if(P3==1){for(n=0;n<1200;n++){record[3][n]=all_unpressed;}}
if(P4==1){for(n=0;n<1200;n++){record[4][n]=all_unpressed;}}
frame_count=-1;cursor_position=0;current_slot=0;
selection_end=148;selection_start=0;loop_number=0;lag=0;
tft.setCursor(1,161);tft.fillRect(1,161,78,30,ILI9341_BLUE);
tft.print(current_slot);
tft.setCursor(81,161);tft.fillRect (81,161,78,30,ILI9341_BLUE);
tft.print(modes[cursor_position]);
tft.setCursor(61,81);tft.fillRect(61,81,40,30,ILI9341_BLUE);
tft.print(selection_start);
tft.setCursor(121,81);tft.fillRect(121,81,40,30,ILI9341_BLUE);
tft.print(selection_end);
tft.setCursor(181,81);tft.fillRect(181,81,40,30,ILI9341_BLUE);
tft.print(loop_number);
}
}
if((button==10) && (current_slot>0)){current_slot–;}
if((button==14) && (current_slot<1999)){current_slot++;}
//14.15.16.17
//10,11,12,13
if((button==16)&&(selection_start<selection_end)&&(selection_end<1199))
{selection_end++;tft.setCursor(121,81);
tft.fillRect(121,81,40,30,ILI9341_BLUE);tft.print(selection_end);}
if((button==12)&&(selection_start<selection_end-1)&&(selection_end>1))
{selection_end--;tft.setCursor(121,81);
tft.fillRect(121,81,40,30,ILI9341_BLUE);tft.print(selection_end);}
if((button==15)&&(selection_start<selection_end-1)&&(selection_start<1198))
{selection_start++;tft.setCursor(61,81);
tft.fillRect(61,81,40,30,ILI9341_BLUE);tft.print(selection_start);}
if((button==11)&&(selection_start<selection_end)&&(selection_start>0))
{selection_start--;tft.setCursor(61,81);
tft.fillRect(61,81,40,30,ILI9341_BLUE);tft.print(selection_start);}
if((button==13)&&(loop_number>0))
{loop_number--;tft.setCursor(181,81);
tft.fillRect(181,81,40,30,ILI9341_BLUE);tft.print(loop_number);}
if((button==17) && (loop_number<100))
{loop_number++;tft.setCursor(181,81);
tft.fillRect(181,81,40,30,ILI9341_BLUE);tft.print(loop_number);}
if((button!=0)&&(mode==-1)){tft.setCursor(1,161);tft.fillRect(1,161,78,30,ILI9341_BLUE);
tft.print(current_slot);}
//tft.setCursor(0,90);tft.print(digitalRead(36));
frame_count++;
if (button==last_button){held++;}
last_button=button;
if ((button==8) && (held>40)){last_button=0;}
if ((button==2) && (held>40)){last_button=0;}
if ((button==4) && (held>60)){last_button=0;delay(30);}
if ((button==6) && (held>60)){last_button=0;delay(30);}
time2=micros();
}
}