Hello Arduino

I have a code in which you can have a "conversation" with your arduino. I am in the process of typing it and when I checked if what I typed so far made sense there were a few errors I was just wondering if you can help me.

void setup() {
  Serial.begin(9600);
    delay(25);
  if(Serial.available()){
  Serial.print("Hello! I'm U.N.O. how are you?");
  delay(2000);
  Serial.print('\n'"type 1, 2, 3 or 4");
  delay(5000);
  Serial.print('\n'"1: Good");
  delay(1000);
  Serial.print('\n'"2: Bad");
  delay(1000);
  Serial.print('\n'"3: Okay");
  delay(1000);
  Serial.print('\n'"4: Great!");
  delay(1000);
  }
}

void loop() {
  delay(25);

}

The errors were:

HelloArduino.ino: In function 'void setup()':
HelloArduino:7: error: expected `)' before string constant
HelloArduino:9: error: expected `)' before string constant
HelloArduino:11: error: expected `)' before string constant
HelloArduino:13: error: expected `)' before string constant
HelloArduino:15: error: expected `)' before string constant

Thanks in advance!

(deleted)

spycatcher2k:
this does not make sense :

Serial.print('\n'"type 1, 2, 3 or 4");
try
Serial.print("\ntype 1, 2, 3 or 4");

Thank you sir...

for helping a noob out.

(deleted)

spycatcher2k:
Errr - I'm not a Sir!

Uh Oh...

Run!!!!

I need more help please.

void setup() {
  Serial.begin(9600);
  Serial.print("Hello! I'm U.N.O. how are you?");
  delay(2000);
  Serial.print('\n');
  delay(50);
  Serial.print("type 1, 2, 3 or 4");
  delay(2000);
  Serial.print('\n');
  delay(50);
  Serial.print("1: Good");
  delay(2000);
  Serial.print('\n');
  delay(50);
  Serial.print("2: Bad");
  delay(2000);
  Serial.print('\n');
  delay(50);
  Serial.print("3: Okay");
  delay(2000);
  Serial.print('\n');
  delay(50);
  Serial.print("4: Great!");
  delay(2000);
  Serial.print('\n');
}

void loop() {
 if (Serial.read(49)) {
          Serial.print("");
        }
  
}

The errors are:

HelloArduino.ino: In function 'void loop()':
HelloArduino:30: error: no matching function for call to 'HardwareSerial::read(int)'
/Users/sharma/Desktop/ .app/Contents/Resources/Java/hardware/arduino/cores/arduino/HardwareSerial.h:60: note: candidates are: virtual int HardwareSerial::read()
HelloArduino:32: error: expected unqualified-id before '}' token
HelloArduino:32: error: expected `;' before '}' token

Serial.read() returns a character, it doesn't return true/false, so you don't pass it a value to check it against, you check if the return value equals a constant.

Ciao I suggest to you ...

you can start to play with ASCII CODE and take confidence :slight_smile:

then use the example that is present into arduino ide,

regards,
Andrea

Shazam360:
I need more help please.

void setup() {

Serial.begin(9600);
  Serial.print("Hello! I'm U.N.O. how are you?");
  delay(2000);
  Serial.print('\n');
  delay(50);
  Serial.print("type 1, 2, 3 or 4");
  delay(2000);
  Serial.print('\n');
  delay(50);
  Serial.print("1: Good");
  delay(2000);
  Serial.print('\n');
  delay(50);
  Serial.print("2: Bad");
  delay(2000);
  Serial.print('\n');
  delay(50);
  Serial.print("3: Okay");
  delay(2000);
  Serial.print('\n');
  delay(50);
  Serial.print("4: Great!");
  delay(2000);
  Serial.print('\n');
}

void loop() {
if (Serial.read(49)) {
          Serial.print("");
        }
 
}





The errors are:





~~~
HelloArduino.ino: In function 'void loop()':

HelloArduino:30: error: no matching function for call to 'HardwareSerial::read(int)'
/Users/sharma/Desktop/ .app/Contents/Resources/Java/hardware/arduino/cores/arduino/HardwareSerial.h:60: note: candidates are: virtual int HardwareSerial::read()
HelloArduino:32: error: expected unqualified-id before '}' token
HelloArduino:32: error: expected `;' before '}' token

void loop() {
 if (Serial.available()) 
  {
     char myChar = Serial.read();
     Serial.println(myChar);
  }
}