Hi everybody, @build_1971 I have made it to project "Crystal Ball" #11 project of the Arduino StarterKit. After I have verified my code, some errors are occurred. I have doubled-checked my code with the code what's already stored in IDE software for the StarterKit, but I can't find the matter. Maybe you can help me out.
#include<LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const int swichPin = 6;
int switchState = 0;
int prevSwitchState = 0;
int reply
void setup(){
lcd.begin(16, 2);
pinMode(switchPin, INPUT);
lcd.print("Ask the");
lcd.setCursor(0, 1);
lcd.print("Crystal Ball!");
}
void loop(){
switchState = digitalRead(switchPin);
if (switchState != prevSwitchState){
if (switchState == LOW){
reply = random(8);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("The ball says:");
lcd.setCursor(0, 1);
switch(reply){
case 0:
lcd.print("Yes");
break;
case 1:
lcd.print("Most likley");
break;
case 2:
lcd.print("Certainly");
break;
case 3:
lcd.print("Outlook good");
break;
case 4:
lcd.print("Unsure");
break;
case 5:
lcd.print("Ask again");
break;
case 6:
lcd.print("Doubtful");
break;
case 7:
lcd.print("No");
break;
}
}
}
prevSwitchState = switchState;
}
Error message are:
C:\Users\janos\Documents\Arduino\Project11\Project11.ino:5:15: error: expected initializer before 'setup'
int prevSwitchState = 0;
^~~~~
C:\Users\janos\Documents\Arduino\Project11\Project11.ino:7:1: error: expected initializer before 'void'
void setup(){
^~~~
C:\Users\janos\Documents\Arduino\Project11\Project11.ino: In function 'void loop()':
C:\Users\janos\Documents\Arduino\Project11\Project11.ino:15:29: error: 'switchPin' was not declared in this scope
switchState = digitalRead(switchPin);
^~~~~~~~~
C:\Users\janos\Documents\Arduino\Project11\Project11.ino:15:29: note: suggested alternative: 'swichPin'
switchState = digitalRead(switchPin);
^~~~~~~~~
swichPin
C:\Users\janos\Documents\Arduino\Project11\Project11.ino:18:7: error: 'reply' was not declared in this scope
reply = random(8);
^~~~~
exit status 1
Compilation error: expected initializer before 'setup'
Sorry, just wondering why are you thinking, I haven't exactly followed your suggestion? I do know the guideline from Paul. I did paste my code in the code-bracket-like post layout look like. Unfortunately, my posted code comes in 3 parts because the capacity isn't big enough for my entire code.
Could you change that?
Unfortunately, that's not the entire code. That's just part1. The entire code is all 3 parts connected to each other what I have posted my post.
Just give you idea what I mean by that.
Here I post the entire code in TEXT Format vs in the Code in . Sure that format is useless, but just that, you get the idea.
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const int switchPin = 6;
int switchState = 0;
int prevSwitchState = 0;
int reply;
void setup() {
lcd.begin(16, 2);
pinMode(switchPin, INPUT);
lcd.print("Ask the");
lcd.setCursor(0, 1);
lcd.print("Crystal Ball!");
}
void loop() {
switchState = digitalRead(switchPin);
if (switchState != prevSwitchState) {
if (switchState == LOW) {
reply = random(8);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("The ball says:");
lcd.setCursor(0, 1);
switch (reply) {
case 0:
lcd.print("Yes");
break;
case 1:
lcd.print("Most likley");
break;
case 2:
lcd.print("Certainly");
break;
case 3:
lcd.print("Outlook good");
break;
case 4:
lcd.print("Unsure");
break;
case 5:
lcd.print("Ask again");
break;
case 6:
lcd.print("Doubtful");
break;
case 7:
lcd.print("No");
break;
}
}
}
prevSwitchState = switchState;
}
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const int switchPin = 6;
int switchState = 0;
int prevSwitchState = 0;
int reply;
void setup() {
lcd.begin(16, 2);
pinMode(switchPin, INPUT);
lcd.print("Ask the");
lcd.setCursor(0, 1);
lcd.print("Crystal Ball!");
}
void loop() {
switchState = digitalRead(switchPin);
if (switchState != prevSwitchState) {
if (switchState == LOW) {
reply = random(8);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("The ball says:");
lcd.setCursor(0, 1);
switch (reply) {
case 0:
lcd.print("Yes");
break;
case 1:
lcd.print("Most likley");
break;
case 2:
lcd.print("Certainly");
break;
case 3:
lcd.print("Outlook good");
break;
case 4:
lcd.print("Unsure");
break;
case 5:
lcd.print("Ask again");
break;
case 6:
lcd.print("Doubtful");
break;
case 7:
lcd.print("No");
break;
}
}
}
prevSwitchState = switchState;
}
If you mean the three parts from you earlier post, the code I posted was cut and pasted from those three windows and I marked it so.
/// from the first window
//...
/// from the second window
//…
/// from the second window
So yeah, posting code without tags you can see why we make our requests.
Code in three windows properly is not entirely terrible, but it is as we see unnecessary, and in three windows or without code tags helpers are reluctant to dive in as there may be missing bits.
Do you mean your sketch now works? Or only that you've sorted the code size vs. tags thing.