I, being new to Arduino started off by making a simple lcd watch which also shows the temperature.
Everything was working fine untill this error came up "a function-definition is not allowed here before '{' token "
And I have done everything to resolve the problem. I wrote the function from scratch. I read somewhere that a function definition can't come within a function, so I made it a Global function(though, personally I somehow don't feel that it's true). But even then the error managed to survive.
Being completely frustrated I don't know what to do. Can anyone please help me out ?
here's my code :-
#include < LiquidCrystal.h >
const int rs = 12,
en = 11,
d4 = 5,
d5 = 4,
d6 = 3,
d7 = 2,
lm = A0;
int input;
float temp;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void tem() //Calculates Temperature
{
int i = analogRead(lm);
float temp = 500.0 * i / 1024;
lcd.print("Temp : ");
lcd.print(temp);
lcd.print(" ^C");
}
void Clock(int h = 0, int m = 0, int s = 0, char ch = 'A') {
int H = h;
char ampm = ch;
void mornight(char ampm) //changes am to am to pm and vice versa
{ //THE RED HIGHLIGHTED ERROR LINE
String AMPM;
if (ampm == 'A')
AMPM = "PM";
else
AMPM = "AM";
}
while (H != 12) //HOUR'S LOOP
{
for (int M = m; M <= 59; M++) //MINUTE'S LOOP
{
for (int S = s; S <= 59; S++) //SECOND'S LOOP
{
delay(1000);
lcd.clear();
if (H < 10) {
lcd.print('0');
lcd.print(H);
lcd.print(':');
} else {
lcd.print(H);
lcd.print(":");
}
if (M < 10) {
lcd.print('0');
lcd.print(M);
lcd.print(':');
} else {
lcd.print(M);
lcd.print(":");
}
if (S < 10) {
lcd.print('0');
lcd.print(S);
lcd.print(AMPM);
} else {
lcd.print(S);
lcd.print(AMPM);
}
lcd.setCursor(0, 1);
tem(); // shows temperature
}
s = 0;
}
m = 0;
if (H == 23) {
H = 1;
mornight(ampm);
} else
H++;
}
}
void setup() {
lcd.begin(16, 2);
lcd.setCursor(0, 1);
Clock(10, 1, 20);
}
void loop() {
}