I'm currently working on a school project. I want the servo to move according to the number of coins selected. I keep getting the error " 'void servoOne()' redeclared as different kind of symbol " I know this has been asked but I'm not sure how to fix this.
Here is my code.
#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--;
}
}
}
It occurs as it clashes between
servoOne
inServo servoOne;
andvoid servoOne()
. Please replaceservoOne
invoid servoOne()
by some other name. (don't forget to replace the function name in function call by your new function name)