#include “TimerOne.h” //Included sketch for timing
#include <LiquidCrystal.h> //Included for LCD screen
LiquidCrystal lcd(12,11,8,5,4,3,2); //sets up the pins for the LCD. Note, cannot use 9 or 10 as these are used by the interrupt timer
int backLight=13;
int F=16683; //Timing for one frame. Change if using PAL instead of NTSC.
int N=0; //Starts the frame counter at 0. When you upload it will start at zero and then begin counting up. After that, releasing SELECT will again reset N to 0.
int ADV=0; //Used as the trigger to move to the next frame once 16666msec have passed
int I=10;int J=20;int i=25; int j=25; //Set some inital values for the variables
int V;
int u=22;int d=24;int l=26;int r=28;int a=30;int b=32;int c=34;int x=36;int y=38;int z=40; int p=42; int q=44; int hom=48; int sta=46; int sel=50;
int U=23; int D=25;int L=27; int R=29; int A=31; int B=33; int C=35; int X=37; int Y=39; int Z=41; int P=43; int Q=45; int HOM=49; int STA=47; int SEL=51;
//Define which pins the buttons are connected to on the arduino
int LED1=54; int LED2=55; int LED3=56; int LED4=57;int LED5=58;int LED6=59;int LED7=60;int LED8=61;
int AState;int BState;int CState;int XState;int YState;int ZState;int UState;int RState;int LState;int DState;int PState;int QState;
int STAState; int SELState; int HOMState;
int aState;int bState;int cState;int xState;int yState;int zState;int uState;int rState;int lState;int dState;int pState; int qState;
int staState; int selState; int homState;
unsigned long time;
void setup(){
Timer1.initialize(F); //This is the timer function from timerone. Every 16666 msec (or whatever F is set to) one frame will tick over.
Timer1.pwm(9,900);
Timer1.attachInterrupt(FrameAdv);
Serial.begin(9600);
pinMode(backLight,OUTPUT); //Turns on the backlight for the LCD
digitalWrite(backLight,HIGH);//Write frame data testing on the LCD
lcd.begin(20, 4);
lcd.clear();
aState=digitalRead(a);// do these have to be done in setup?
bState=digitalRead(b);
cState=digitalRead©;
xState=digitalRead(x);
yState=digitalRead(y);
zState=digitalRead(z);
uState=digitalRead(u);
dState=digitalRead(d);
lState=digitalRead(l);
rState=digitalRead®;
pState=digitalRead§;
qState=digitalRead(q);
AState=digitalRead(A);
BState=digitalRead(B);
CState=digitalRead©;
XState=digitalRead(X);
YState=digitalRead(Y);
ZState=digitalRead(Z);
UState=digitalRead(U);
DState=digitalRead(D);
LState=digitalRead(L);
RState=digitalRead®;
PState=digitalRead§;
QState=digitalRead(Q);
pinMode(a,INPUT); // Sets all the arduinos pins to initially read inputs and not output unless instructed.
pinMode(b,INPUT); //* Can this be done with a <<statement
pinMode(c,INPUT);
pinMode(x,INPUT);
pinMode(y,INPUT);
pinMode(z,INPUT);
pinMode(r,INPUT);
pinMode(l,INPUT);
pinMode(d,INPUT);
pinMode(u,INPUT);
pinMode(p,INPUT);
pinMode(q,INPUT);
pinMode(sel,INPUT);
pinMode(sta,INPUT);
pinMode(hom,INPUT);
pinMode(A,INPUT);
pinMode(B,INPUT);
pinMode(C,INPUT);
pinMode(X,INPUT);
pinMode(Y,INPUT);
pinMode(Z,INPUT);
pinMode(R,INPUT);
pinMode(L,INPUT);
pinMode(D,INPUT);
pinMode(U,INPUT);
pinMode(P,INPUT);
pinMode(Q,INPUT);
pinMode(SEL,INPUT);
pinMode(STA,INPUT);
pinMode(HOM,INPUT);
pinMode(LED1,OUTPUT);
pinMode(LED2,OUTPUT);
pinMode(LED3,OUTPUT);
pinMode(LED4,OUTPUT);
}
void FrameAdv(){ADV=1;}//When the timer ticks over, set advance integer to 1 so that the next frame starts
void press (int start, int finish, int m1, int m2, int m3, int m4) //This is the function that makes it easy to input commands, instead of having to
{if(N==start){pinMode(m1,OUTPUT);digitalWrite(m1,LOW);} //Type everything each time.
if(N==finish){digitalWrite(m1,HIGH);pinMode(m1,INPUT);}//The syntax is press(frame to start on, frame to stop on, button/direction 1,2,3,4)
if(N==start){pinMode(m2,OUTPUT);digitalWrite(m2,LOW);} // If you need more than 4 buttons/directions pressed on a set frame, just set two press functions.
if(N==finish){digitalWrite(m2,HIGH);pinMode(m2,INPUT);}
if(N==start){pinMode(m3,OUTPUT);digitalWrite(m3,LOW);}
if(N==finish){digitalWrite(m3,HIGH);pinMode(m3,INPUT);}
if(N==start){pinMode(m4,OUTPUT);digitalWrite(m4,LOW);}
if(N==finish){digitalWrite(m4,HIGH);pinMode(m4,INPUT);}}
void press (int start, int finish, int m1, int m2, int m3)
{if(N==start){pinMode(m1,OUTPUT);digitalWrite(m1,LOW);}
if(N==finish){digitalWrite(m1,HIGH);pinMode(m1,INPUT);}
if(N==start){pinMode(m2,OUTPUT);digitalWrite(m2,LOW);}
if(N==finish){digitalWrite(m2,HIGH);pinMode(m2,INPUT);}
if(N==start){pinMode(m3,OUTPUT);digitalWrite(m3,LOW);}
if(N==finish){digitalWrite(m3,HIGH);pinMode(m3,INPUT);}}
void press (int start, int finish, int m1, int m2)
{if(N==start){pinMode(m1,OUTPUT);digitalWrite(m1,LOW);}
if(N==finish){digitalWrite(m1,HIGH);pinMode(m1,INPUT);}
if(N==start){pinMode(m2,OUTPUT);digitalWrite(m2,LOW);}
if(N==finish){digitalWrite(m2,HIGH);pinMode(m2,INPUT);}}
void press (int start, int finish, int m1)
{if(N==start){pinMode(m1,OUTPUT);digitalWrite(m1,LOW);}
if(N==finish){digitalWrite(m1,HIGH);pinMode(m1,INPUT);}}
int check(int V1, int V2){
if( digitalRead(V2)==LOW){digitalWrite(V1, HIGH);
if(digitalRead(U)==LOW){if(digitalRead(U)!=UState){V=V+5;}} //
if(digitalRead(L)==LOW){if(digitalRead(L)!=LState){V=V-1;}}
if(digitalRead(D)==LOW){if(digitalRead(D)!=DState){V=V-5;}}
if(digitalRead®==LOW){if(digitalRead®!=RState){V=V+1;}}
if(digitalRead(u)==LOW){if(digitalRead(u)!=uState){V=V+20;}}
if(digitalRead(l)==LOW){if(digitalRead(l)!=lState){V=V+10;}}
if(digitalRead(d)==LOW){if(digitalRead(d)!=dState){V=V-100;}}
if(digitalRead®==LOW){if(digitalRead®!=rState){V=V+50;}}
}}
void loop(){ // The start of the working part of the script
if (ADV==1){
//press(1,2,D); press(3,4,A); press(26,27,R);press(I,I+1,A);//press(I,I+1,A);
//press(1,2,R,U,B); press(I,I+1,A);
press(1,2,L); press(1,4,D);press(3,5,R); press(6,8,D,L); press(7,8,B,X);
press(I,63,d);
check(LED1, P); I=I+V; V=0; //pressing L decreases I by 1 and pressing D decreases I by 5.
check(LED2, Q); J=J+V; V=0;
check(LED3, p); i=i+V; V=0;
check(LED4, q); j=j+V; V=0;
if(digitalRead(SEL)==HIGH){if(digitalRead(SEL)!=SELState){N=0;}digitalWrite(LED1,LOW);digitalWrite(LED2,LOW);digitalWrite(LED3,LOW);digitalWrite(LED4,LOW); }
if(digitalRead(sel)==LOW){lcd.clear();
if(digitalRead(a)==LOW){if(digitalRead(a)!=aState){l=28;r=26;L=29;R=27;}}
if(digitalRead(b)==LOW){if(digitalRead(b)!=bState){r=28;l=26;L=27;R=29;}}
if(digitalRead(x)==LOW){if(digitalRead(x)!=xState){u=24;d=22;U=25;D=23;}}
if(digitalRead(y)==LOW){if(digitalRead(y)!=yState){u=22;d=24;U=23;D=25;}}
if(digitalRead©==LOW){if(digitalRead©!=cState){I=0;i=0;J=0;j=0;}}
if(digitalRead(z)==LOW){if(digitalRead(z)!=cState){J=I+1;i=I+2;j=I+3;}}}
// int r=28;int l=26;int L=27; int R=29;int u=22;int d=24;int U=23; int D=25;
UState=digitalRead(U);DState=digitalRead(D);LState=digitalRead(L);RState=digitalRead®;
PState=digitalRead§;QState=digitalRead(Q);AState=digitalRead(A); //This makes the arduino acknowledge the current state of the buttons.
uState=digitalRead(u);dState=digitalRead(d);lState=digitalRead(l);rState=digitalRead®;
pState=digitalRead§;qState=digitalRead(q);aState=digitalRead(a);bState=digitalRead(b);cState=digitalRead©;xState=digitalRead(x);yState=digitalRead(y); zState=digitalRead(z);
SELState=digitalRead(SEL);selState=digitalRead(sel);
lcd.clear();
lcd.setCursor(0,0);lcd.print(“I=”);lcd.print(I);
lcd.setCursor(0,1);lcd.print(“J=”);lcd.print(J);
lcd.setCursor(0,2);lcd.print(“i=”);lcd.print(i);
lcd.setCursor(0,3);lcd.print(“j=”);lcd.print(j);
lcd.setCursor(10,3);lcd.print(“N=”);lcd.print(N);
if(l==26){lcd.setCursor(10,0);lcd.print(“1P2P”);}
if(l==28){lcd.setCursor(10,0);lcd.print(“2P1P”);}
if(u==22){lcd.setCursor(15,0);lcd.print(“Norm”);}
if(u==24){lcd.setCursor(15,0);lcd.print(“Inve”);}
ADV=0;
N=N+1;
}
}