So I am using a void in my code for a color combo lock. This was my code:
void wait(int TimeWaiting){
int StartTime=millis();
int FinishTime=StartTime+TimeWaiting;
while (millis()<FinishTime){
lcd.clear();
lcd.setCursor(0,0);
lcd.print("waiting");
delay(50);
lcd.print("waiting.");
delay(50);
lcd.print("waiting..");
delay(50);
lcd.pritn("waiting...");
delay(50);
}
}
I keep on getting an error message saying that, "a function-definition is not allowed here before '{' token. I don't really know how to fix this. Thanks.
(deleted)
Code so far (I have not finished):
/*
This is a code for a color combo lock.
*/
#include <LiquidCrystal.h>
const int rs = 12, en = 11, d4 = 4, d5 = 5, d6 = 6, d7 = 7;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
const int YellowPin=31;
const int GreenPin=33;
const int BluePin=35;
const int RedPin=37;
bool YellowPressed=false;
bool GreenPressed=false;
bool BluePressed=false;
bool RedPressed=false;
void setup() {
pinMode(31,INPUT); //Yellow button
pinMode(33, INPUT); //Green Button
pinMode(35, INPUT); //Blue Button
pinMode(37, INPUT); //Red Button
lcd.begin(16, 2);
lcd.print("Hello,");
}
void loop() {
if (digitalRead(YellowPin)==HIGH){
YellowPressed=true;
}
if (digitalRead(GreenPin)==HIGH){
GreenPressed=true;
}
if (digitalRead(BluePin)==HIGH){
BluePressed=true;
}
if (digitalRead(RedPin)==HIGH){
RedPressed=true;
}
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
lcd.print("My name is ");//need to add in name
delay(600);
lcd.clear();
lcd.setCursor(0,0); //set cursor to first collumn first row
lcd.print("To get in, please complete");
lcd.setCursor(0,1); //set cursor t first collum second row
lcd.print("the following instructions");
delay(300);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("First,");
lcd.setCursor(0,1);
lcd.print("press the green button");
delay(300);
void wait(int TimeWaiting){
int StartTime=millis();
int FinishTime=StartTime+TimeWaiting;
while (millis()<FinishTime){
lcd.clear();
lcd.setCursor(0,0);
lcd.print("waiting");
delay(50);
lcd.print("waiting.");
delay(50);
lcd.print("waiting..");
delay(50);
lcd.pritn("waiting...");
delay(50);
}
}
while(YellowPressed==false && GreenPressed==false && BluePressed==false && RedPressed==false){
wait(200);
}
if (GreenPressed==true){
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Button ")
}
}
Error Message:
/tmp/115527127/Color_Combo_Lock_/Color_Combo_Lock_.ino: In function 'void loop()':
/tmp/115527127/Color_Combo_Lock_/Color_Combo_Lock_.ino:56:29: error: a function-definition is not allowed here before '{' token
/tmp/115527127/Color_Combo_Lock_/Color_Combo_Lock_.ino:76:1: error: expected '}' at end of input
exit status 1
(deleted)
I suggest that you study a C/C++ tutorial to learn the language a bit (more).
Those 'things' are not called voids, they are called functions.
You have defined your function inside another function. Your function needs to be outside loop() and you call it from e.g. loop().
(deleted)
The error resides between these lines:
delay(300);
void wait(int TimeWaiting){
Here you try to define a function wait() without first terminating the definition of loop().
Solution: cut entire void wait() {...} and paste it at the end of your code.
And learn to post code properly, if you want to get continued help.
To make it easy for people to help you please modify your post and use the code button </> so your code looks like this
and is easy to copy to a text editor. See How to use the Forum
...R