2017-08-31 176 views
1

我目前正在開展一個學校項目。我希望伺服器根據所選硬幣的數量進行移動。我不斷收到錯誤「'void servoOne()'重新聲明爲不同類型的符號」我知道這已被問到,但我不知道如何解決這個問題。在Arduino中重新聲明爲不同類型的符號

這是我的代碼。

#include <LiquidCrystal.h> 
#include <Keypad.h> 
#include <Servo.h> 

Servo servoOne; 

String sharp=""; 
int piso=0; 
int lima=0; 
int sampu=0; 

String input=""; 
String remlast = ""; 

LiquidCrystal lcd(A0, A1, A2, A3, A4, A5);//RS,EN,D4,D5,D6,D7 


const byte Rows= 4; //number of rows on the keypad i.e. 4 
const byte Cols= 3; //number of columns on the keypad i,e, 3 

//we will definne the key map as on the key pad: 

char keymap[Rows][Cols]={ 
    {'1', '2', '3'}, 
    {'4', '5', '6'}, 
    {'7', '8', '9'}, 
    {'*', '0', '#'} 
}; 

byte rPins[Rows]= {3,4,5,6}; //Rows 0 to 3 
byte cPins[Cols]= {7,8,9}; //Columns 0 to 2 

Keypad kpd= Keypad(makeKeymap(keymap), rPins, cPins, Rows, Cols); 

void setup() { 
    // put your setup code here, to run once: 
lcd.begin(20,4); 
servoOne.attach(10); 
} 

void loop() { 
    char key2 = kpd.getKey(); 


    if (key2 != NO_KEY) 
    { 
     lcd.print(key2); 

     if (sharp == "") 
     { 
      input+=key2; 
      remlast = input; 
      remlast.replace("*",""); 
      remlast.replace("#",""); 
      piso = remlast.toInt(); 
     } 
     else if (sharp == "five") 
     { 
      input+=key2; 
      remlast = input; 
      remlast.replace("*",""); 
      remlast.replace("#",""); 
      lima = remlast.toInt(); 
     } 
     else if (sharp == "ten") 
     { 
      input+=key2; 
      remlast = input; 
      remlast.replace("*",""); 
      remlast.replace("#",""); 
      sampu = remlast.toInt(); 
     } 

     if(key2=='*' && sharp!=NULL) 
     { 
     lcd.rightToLeft(); 
     sharp=""; 
     piso=0; 
     lima=0; 
     sampu=0; 
     input=""; 
     remlast=""; 
     } 

     if (sharp=="ten" && key2=='#') 
     { 
     sharp = "out"; 
     lcd.clear(); 
     lcd.print(piso); 
     lcd.print(lima); 
     lcd.print(sampu); 
     servoOne(); 
     } 

    else if (sharp=="five" && key2=='#') 
     { 
      lcd.clear(); 
      lcd.print("10-peso="); 
      lcd.setCursor(0,1); 
      lcd.print("(*)Erase (#)Enter"); 
      lcd.setCursor(8,0); 
      sharp="ten"; 
      input = 0;  
     } 

    else if (key2=='#') 
     { 
     lcd.clear(); 
     lcd.print("5-peso="); 
     lcd.setCursor(0,1); 
     lcd.print("(*)Erase (#)Enter"); 
     lcd.setCursor(7,0); 
     sharp="five"; 
     input = 0; 

     } 
     if (key2=='*') 
     { 
     lcd.clear(); 
     lcd.print("1-peso="); 
     lcd.setCursor(0,1); 
     lcd.print("(*)Erase (#)Enter"); 
     lcd.setCursor(7,0); 
     } 

     } 
    } 

//--------------------SERVO ONE--------------------// 
void servoOne() 
{ 
    servoOne.write(70); 
    delay(10); 
    while(piso>0) 
    { 
    int x = piso; 
    while(x>0) 
    { 
     servoOne.write(170); 
     delay(200); 
     servoOne.write(40); 
     delay(200); 
     x--; 
    } 
    } 
} 
+3

您有一個函數和一個全局變量,它們都被稱爲'servoOne'。將其中一個重命名爲其他東西。 – WolfLink

回答

2

它發生,因爲它在Servo servoOne;void servoOne()servoOne之間相撞。請用其他名稱替換void servoOne()中的servoOne。 (不要忘記用函數名稱替換函數調用中的函數名稱)