0
#include <LiquidCrystal.h>

int trigPin = 13;  //sensor's trigger pin connected to pin 13
int echoPin = 7;  //sensor's echo pin connected to pin 11
float pingTime;  //time for the ping to hit the target and back
float ss;  //we will calculate the speed of sound
float td = 13; //target distance.



void setup() {
  // put your setup code here, to run once:

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

  Serial.begin(9600);
  pinMode(trigPin,OUTPUT);  //TRIG AS OUTPUT
  pinMode(echoPin,INPUT);  //EHO AS AN INPUT


  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.println(ss);

}

void loop() {
  // put your main code here, to run repeatedly:

  digitalWrite(trigPin,LOW);  //set trig pin low.
  delayMicroseconds(2000);
  digitalWrite(trigPin,HIGH);
  delayMicroseconds(100);
  digitalWrite(trigPin,LOW);
  pingTime = pulseIn(echoPin,HIGH);  //measure ping time traveltime in microseconds.
  ss= 2*td / pingTime;  //gives us speed in inches per microseconds.
  ss=ss/63360*1000000*3600;  //gives us speed in miles per hour.
  Serial.print("The speed of sound is ");
  Serial.print(ss);
  Serial.println(" miles per hour"); 

  // Turn off the blinking cursor:
  lcd.noBlink();
  delay(3000);
  // Turn on the blinking cursor:
  lcd.blink(0);
  delay(3000);

}
Majenko
  • 103,876
  • 5
  • 75
  • 133
Adam
  • 19
  • 1
  • 1

3 Answers3

2

The culprits are the no-break spaces (U+00A0) you sometimes use in your indentation. Each of them, when encoded in UTF-8, is represented by the pair of bytes 0xc2 0xa0 (or 0302 0240 in octal). You should indent with regular spaces (U+0020) instead.

Specifically, you have no-break spaces as the first characters of each of the following 8 lines:

lcd.begin(16, 2);
// Print a message to the LCD.
lcd.println(ss);
[...]
lcd.noBlink();
delay(3000);
// Turn on the blinking cursor:
lcd.blink(0);
delay(3000);
Edgar Bonet
  • 39,449
  • 4
  • 36
  • 72
1

Beware when you copy code from sites which have formatead fonts in their content. As you copy and paste these font-formatead codes, chances are that you copy the font's formats as well. Once you paste these formatead fonts on your code, the text editor from the Arduino IDE will not recognize the special characters used on the font's formatting; thus, it will not show them on your screen. However, the compiler will read them and will strive to compile them as if they were part of your code. Since the compiler does not "understand" these special characters, it will warn you about their existence by identifying them as "stray" pieces of code. This is why some code-related sites, such as GitHub, gives you the opportunity of copying RAW CODE, so you do not copy the formatead fonts that some developers use to showcase their much appreciated contributions. I sincerely hope this works for you. Best regards.

1

Just try to removes extra spaces that are outside the scopes (curly braces { and }) and it'll work fine.

gre_gor
  • 1,669
  • 4
  • 18
  • 28