"Crystal Ball" 11# Arduino StarterKit- Coding erros are ouccur

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'

int reply

Missing semicolon

There may be other errors but as you did not put the code in code tags I did not look further

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the < CODE/ > icon above the compose window) to make it easier to read and copy for examination

https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum

Hi @UKHeliBob, thank you for your reply.

Sorry, where about is the semicolon is missing?

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? :slightly_smiling_face:

I have never seen any limit to what can be put in code tags.

You've heard this before, I am sure, but here's one easy way to post code:

First, use the Autoformat tool in the IDE to make your code pretty(er).

Then copy the entire sketch.

Come back here, use the <CODE/> tool in the message composition window tool bar and

type or paste code here

type or past your code where it sez.

a7

It's the line @UKHeliBob quoted

int reply

Surely you can find that, or find it with the finding ability of your text editor.

a7

Let's look at the typos found in your code:

  1. Mr. @UKHeliBob has already pointed

this out and indicated to you where the error is:
Line 6: int reply correct: int reply;

  1. Line 3: const int swichPin = 6; correct: const int switchPin = 6;
    The variables used in your code have the letter t.
1 Like

@ruilviana thank you it worked. :blush:

@alto777.

Hang on a minute: First, your reply is impolite towards me. I didn't like it right up to me. You don't know me!
Quote on quote:

"I have never seen any limit to what can be put in code tags.

You've heard this before, I am sure, but here's one easy way to post code:

First, use the Autoformat tool in the IDE to make your code pretty(er).

Then copy the entire sketch."

First I have posted the code in Autoformat. Try itself and post the entire code in the code-bracket. If you manage that then we are talking again.

1 Like

But I do! Sorry I offended you with my remarks, which I always try to make offensively neutral.

You've been working through some guide book diligently making progress, surely you have posted code before, or been told, or read, how to do it.

I wrote my instructions for you as well as for the thousands of other ppl (dozens? (three?)) reading along, who may have yet to post code.

a7

Code in tags. Not sure what you were doing wrong or weren't doing right.

/// from the first window

#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:
        
/// from the second window

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");        
        
/// from the third window        

break;
      }
    }
  }
  prevSwitchState = switchState;
}

If that's all your code we done. Again, sorry to offend.

a7

No worries! @alto777 :blush:

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;
}

Sorry. @alto777 now it worked!

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.

a7

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.