Go Down

Topic: arduino programing error.. HELP>>!!! (Read 490 times) previous topic - next topic

ianfeng

can anyone help me with my programing?
my code is

const int lcdPin = (10,11,12,13,14,15,16);    
const int switchpin = 2;

// variables will change:
int switchState = 0;          
int potPin = 2;
int buzzerPin = 1;
int greenPin = 11;
int greenbuttonPin = 13;
int bluePin = 9;
int bluetiltPin = 15;
int redPin = 10;
int redbuttonPin = 17;
int yellowPin = 12;
int yellowbuttonPin = 9;
int color =0;
boolean chosen,buttonPushed = false;
long startMillis,previousMillis;


int switchStateGreen,switchStateRed,switchStateBlue,switchStateYellow = LOW;

void setup() {
 // initialize the LCD pin as an output:
 pinMode(lcdPin, OUTPUT);      
 // initialize the switch pin as an input:
 pinMode(potPin, INPUT);

 // initialize the green LED pin as an output:
 pinMode(greenPin, OUTPUT);
 // initialize the greenarm button pin as an input:
 pinMode(greenbuttonPin, INPUT);

 // initialize the blue LED pin as an output:
 pinMode(bluePin, OUTPUT);
 // initialize the bluearm tilt pin as an input:
 pinMode(bluetiltPin, INPUT);

 // initialize the red LED pin as an output:
 pinMode(redPin, OUTPUT);
 // initialize the redarm button pin as an input:
 pinMode(redbuttonPin, INPUT);

 // initialize the yellow LED pin as an output:
 pinMode(yellowPin, OUTPUT);
 // initialize the yellowarm button pin as an input:
 pinMode(yellowbuttonPin, INPUT);
}

void loop(){
 
 //choose level
 while(!chosen){
   lcd.print("ChooseMode");
   level = analogRead(potPin);
   if (level <300){
     level = 1;
   }
   else if (level >300 && level <600){
     if (wins >5 ){
       level = 2;
     }
     else {
       lcd.setCursor(0,0);
       lcd.print("Beat level 1");
       lcd.setCursor(0,1);
       lcd.print("first!");
     }
   }
   else if (level >600){
     if (wins >10 ){
       level = 3;
     }
     else {
       lcd.setCursor(0,0);
       lcd.print("Beat level 2");
       lcd.setCursor(0,1);
       lcd.print("first!");
     }

   }
   chosen = true;
 }

 //play levels
 while(level==1){
   level1();
 }
 while(level==2){
   level2();
 }
 while(level==3){
   level3();
 }


}




void checkButtons(){
 switchStateGreen = digitalRead(greenbuttonPin);
 switchStateBlue = digitalRead(bluetiltPin);
 switchStateRed = digitalRead(redbuttonPin);
 switchStateYellow = digitalRead(yellowbuttonPin);

 if (switchStateYellow == HIGH || switchStateBlue == HIGH ||switchStateRed == HIGH ||switchStateBlue == HIGH) {
   buttonPushed = true;
 }
}



void level1() {
 lcd.print("Challenge Mode");
 delay(2000);

 lcd.print("ready...");

 //which button? Random colour light up
 //want to select random color



 color = int(random(1,4));

 if (color = 1) {
   //light Green ARM
   startMillis = millis();
   while( startMillis - previousMillis > 1000){
     previousMillis = millis();

     //light green arm
     digitalWrite(greenPin,HIGH);
     lcd.print("green");

     while (!buttonPushed) {
       //check button state;
       checkButtons();
     }
     buttonPushed = false;

     if (switchStateRed == HIGH ||switchStateBlue == HIGH ||switchStateYellow == HIGH ) {
       lcd.print("incorrect");
       delay(2000);
       digitalWrite(greenPin,LOW);
       wins=0;
     }
     else if (switchStateGreen == HIGH) {
       lcd.print("correct");
       delay(2000);
       chosen = true;
       digitalWrite(buzzerPin,HIGH);
       delay(1000);
       digitalWrite(greenPin,LOW);
       wins++;
     }
   }
   lcd.print("Missed Green!");
   ///END of Green Section
 }




 if (color = 2) {
   //light Blue ARM
   startMillis = millis();
   while( startMillis - previousMillis > 1000){
     previousMillis = millis();

     //light blue arm
     digitalWrite(bluePin,HIGH);
     lcd.print("blue");

     while (!buttonPushed) {
       //check button state;
       checkButtons();
     }
     buttonPushed = false;

     if (switchStateRed == HIGH ||switchStateBlue == HIGH ||switchStateYellow == HIGH ) {
       lcd.print("incorrect");
       delay(2000);
       digitalWrite(bluePin,LOW);
       wins=0;

     }
     else if (switchStateBlue == HIGH) {
       lcd.print("correct");
       delay(2000);
       chosen = true;
       digitalWrite(buzzerPin,HIGH);
       delay(1000);
       digitalWrite(bluePin,LOW);
       wins++;
     }
   }
   lcd.print("Missed Blue!");
   ///END of Blue Section
 }


 if (color = 3) {
   //light Red ARM
   startMillis = millis();
   while( startMillis - previousMillis > 1000){
     previousMillis = millis();

     //light red arm
     digitalWrite(redPin,HIGH);
     lcd.print("red");

     while (!buttonPushed) {
       //check button state;
       checkButtons();
     }
     buttonPushed = false;

     if (switchStateRed == HIGH ||switchStateRed == HIGH ||switchStateYellow == HIGH ) {
       lcd.print("incorrect");
       delay(2000);
       digitalWrite(redPin,LOW);    

     }
     else if (switchStateRed == HIGH) {
       lcd.print("correct");
       delay(2000);
       chosen = true;
       digitalWrite(buzzerPin,HIGH);
       delay(1000);
       digitalWrite(redPin,LOW);
     }
   }
   lcd.print("Missed Red!");
   ///END of Red Section
 }


 if (color = 4) {
   //light Yellow ARM
   startMillis = millis();
   while( startMillis - previousMillis > 1000){
     previousMillis = millis();

     //light yellow arm
     digitalWrite(yellowPin,HIGH);
     lcd.print("yellow");

     while (!buttonPushed) {
       //check button state;
       checkButtons();
     }
     buttonPushed = false;

     if (switchStateYellow == HIGH ||switchStateYellow == HIGH ||switchStateYellow == HIGH ) {
       lcd.print("incorrect");
       delay(2000);
       digitalWrite(yellowPin,LOW);    
       wins=0;
     }
     else if (switchStateYellow == HIGH) {
       lcd.print("correct");
       delay(2000);
       chosen = true;
       digitalWrite(buzzerPin,HIGH);
       delay(1000);
       digitalWrite(yellowPin,LOW);
       wins++;
     }
   }
   lcd.print("Missed Yellow!");
   ///END of Yellow Section
 }

 //when 5 wins in a row drop the ball out
 if (wins >5){
   digitalWrite(ballSolenoid, HIGH);
   chosen =false;
   level =0;
 }
}

i had error on
toy_programingggf.cpp: In function 'void loop()':
toy_programingggf:53: error: 'lcd' was not declared in this scope
toy_programingggf:54: error: 'level' was not declared in this scope
toy_programingggf:59: error: 'wins' was not declared in this scope
toy_programingggf:70: error: 'wins' was not declared in this scope
toy_programingggf:85: error: 'level' was not declared in this scope
toy_programingggf:88: error: 'level' was not declared in this scope
toy_programingggf:89: error: 'level2' was not declared in this scope
toy_programingggf:91: error: 'level' was not declared in this scope
toy_programingggf:92: error: 'level3' was not declared in this scope
toy_programingggf.cpp: In function 'void level1()':
toy_programingggf:115: error: 'lcd' was not declared in this scope
toy_programingggf:147: error: 'wins' was not declared in this scope
toy_programingggf:156: error: 'wins' was not declared in this scope
toy_programingggf:186: error: 'wins' was not declared in this scope
toy_programingggf:196: error: 'wins' was not declared in this scope
toy_programingggf:260: error: 'wins' was not declared in this scope
toy_programingggf:269: error: 'wins' was not declared in this scope
toy_programingggf:277: error: 'wins' was not declared in this scope
toy_programingggf:278: error: 'ballSolenoid' was not declared in this scope
toy_programingggf:280: error: 'level' was not declared in this scope


i cant fix this.. pls help..

Nick Gammon

Why is this a poll, where we can choose between "d", "d" and "d"?

And please use the "code" tag (select your code and hit the # button).
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

AWOL

#2
Apr 16, 2011, 10:50 am Last Edit: Apr 16, 2011, 11:01 am by AWOL Reason: 1
Quote
toy_programingggf:53: error: 'lcd' was not declared in this scope


I don't think that the compiler error message could be much clearer.
You haven't declared anything called "lcd".

I think there may be a dangerous assumption going on here:
Code: [Select]
int switchStateGreen,switchStateRed,switchStateBlue,switchStateYellow = LOW;
.
Fortunately, your are lucky, because LOW == 0, which is what got written to all those variables anyway.

(Vote for d - Yay!)
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Nick Gammon

Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

AWOL

No, not that one!

Code: [Select]
pinMode(lcdPin, OUTPUT);     
Good luck with that one.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Nick Gammon

I don't think you connected the grounds, Dave.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy