Made some progress with the game. Thought I was almost done with the coding but I'm stuck and will seek help with it. Current progress is after the break. Decided to start commenting my coding as well so I don't forget everything if I try to look at something later.
int count=0;
int currentOn=7; //currentOn variable is the current LED position.
void setup()
{
/* introSeq2();
introSeq2();
introSeq();
count=0;
introSeq();
count=0;
introSeq();
count=0;*/
Serial.begin(9600);
digitalWrite(currentOn,HIGH);
}
void loop() {
leftright();
}
//(***************Break up for first IntroSeq ********************************************
void introSeq2(){
for (int i=2; i<12; i++){
digitalWrite(i,HIGH);
delay(100);
digitalWrite(i,LOW);}
}
//(***************Break up for Second IntroSeq ********************************************
void introSeq(){
for(int j=6; j>1; j--){
digitalWrite(j,HIGH);
digitalWrite(j+1+count,HIGH);
delay(200);
digitalWrite(j,LOW);
digitalWrite(j+1+count,LOW);
count += + 2;}}
// ****************Break up for Move Left *********************************
int leftright(){
int right = analogRead(0); //Read value from joystick right
int left = analogRead(1); //or left.
Serial.println(right);
Serial.println(left);
delay(500); //Large delay for testing purposes.
if (right == 0)
{
digitalWrite(currentOn,LOW); //The current LED is turned off
currentOn-=1; //the position is decreased by one
digitalWrite(currentOn,HIGH); //and the new current LED is set to high.
while(currentOn <= 15)
{
delay(300);
digitalWrite(currentOn,LOW);
currentOn+=1;
digitalWrite(currentOn,HIGH);
}
}
if (left == 0) //Same code as previous if statement except in the opposite direction.
{
digitalWrite(currentOn,LOW);
currentOn+=1;
digitalWrite(currentOn,HIGH);
while(currentOn >= 0)
{
delay(300);
digitalWrite(currentOn,LOW);
currentOn-=1;
digitalWrite(currentOn,HIGH);
}
}
}
No comments:
Post a Comment