millisec help

hi guys. I got an ultrasonic sensor(PARALLAX) and a led. I want to power up my ultrasonic sensor according to the ledState but I get exit status 1 and stray \302 error. help me plzz. here is my code

const int pingPin = 7;
int ledPin = 13; // the number of the LED pin
int ledState = LOW; // ledState used to set the LED
unsigned long previousMillis = 0; // will store last time LED was updated
long OnTime = 2000; // milliseconds of on-time
long OffTime = 30000; // milliseconds of off-time

void setup()
{
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
}

void loop()
{
// check to see if it's time to change the state of the LED
unsigned long currentMillis = millis();
long duration, inches, cm;

if((ledState == HIGH) && (currentMillis - previousMillis >= OnTime))
{
ledState = LOW; // Turn it off
previousMillis = currentMillis; // Remember the time
digitalWrite(ledPin, ledState); // Update the actual LED
}
else if ((ledState == LOW) && (currentMillis - previousMillis >= OffTime))
{
ledState = HIGH; // turn it on
previousMillis = currentMillis; // Remember the time
digitalWrite(ledPin, ledState); // Update the actual LED

pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(5);
digitalWrite(pingPin, LOW);

pinMode(pingPin, INPUT);
duration = pulseIn(pingPin, HIGH);

inches = microsecondsToInches(duration);
cm = microsecondsToCentimeters(duration);

Serial.print(inches);
Serial.print("in, ");
Serial.print(cm);
Serial.print("cm");
Serial.println();

delay(100);

}
}

long microsecondsToInches(long microseconds) {

return microseconds / 74 / 2;
}

long microsecondsToCentimeters(long microseconds) {

return microseconds / 29 / 2;
}

When I compiled the code you improperly posted, I got:

Sketch uses 3,982 bytes (1%) of program storage space. Maximum is 253,952 bytes.
Global variables use 224 bytes (2%) of dynamic memory, leaving 7,968 bytes for local variables. Maximum is 8,192 bytes.

That is the result most people strive for.

If you got different results, post ALL of the error messages, along with the board you are compiling for and the version of the IDE you are using and the OS you are using.

You aren't stuck in the XP stone ages, are you?

You have a copy problem; probably copied something from a website.

Remove everything from the current sketch, copy the code that you posted above back into the sketch and compile.

what do I have to change?

You don't have to change anything; just copy the code from this web page and paste it into your sketch (or a new sketch) and it will compile.

Arduino: 1.6.13 (Windows Store 1.6.13.0) (Windows 10), Board: "Arduino/Genuino Uno"

^

sketch_jan05a:52: error: stray '\240' in program

sketch_jan05a:54: error: stray '\302' in program

 }

^

sketch_jan05a:54: error: stray '\240' in program

sketch_jan05a:58: error: stray '\302' in program

Â

^

sketch_jan05a:58: error: stray '\240' in program

sketch_jan05a:59: error: stray '\302' in program

 return microseconds / 74 / 2;

^

sketch_jan05a:59: error: stray '\240' in program

sketch_jan05a:64: error: stray '\302' in program

 return microseconds / 29 / 2;

^

sketch_jan05a:64: error: stray '\240' in program

exit status 1
stray '\302' in program

I'm getting the same error

Hmm, neither @Pauls nor me get the error. Code simply compiles. I will post you a version shortly.

const int pingPin = 7;
int ledPin =  13;      // the number of the LED pin
int ledState = LOW;             // ledState used to set the LED
unsigned long previousMillis = 0;        // will store last time LED was updated
long OnTime = 2000;           // milliseconds of on-time
long OffTime = 30000;          // milliseconds of off-time

void setup()
{
  Serial.begin(9600);
  pinMode(ledPin, OUTPUT);
}

void loop()
{
  // check to see if it's time to change the state of the LED
  unsigned long currentMillis = millis();
  long duration, inches, cm;

  if ((ledState == HIGH) && (currentMillis - previousMillis >= OnTime))
  {
    ledState = LOW;  // Turn it off
    previousMillis = currentMillis;  // Remember the time
    digitalWrite(ledPin, ledState);  // Update the actual LED
  }
  else if ((ledState == LOW) && (currentMillis - previousMillis >= OffTime))
  {
    ledState = HIGH;  // turn it on
    previousMillis = currentMillis;   // Remember the time
    digitalWrite(ledPin, ledState);    // Update the actual LED

    pinMode(pingPin, OUTPUT);
    digitalWrite(pingPin, LOW);
    delayMicroseconds(2);
    digitalWrite(pingPin, HIGH);
    delayMicroseconds(5);
    digitalWrite(pingPin, LOW);

    pinMode(pingPin, INPUT);
    duration = pulseIn(pingPin, HIGH);


    inches = microsecondsToInches(duration);
    cm = microsecondsToCentimeters(duration);

    Serial.print(inches);
    Serial.print("in, ");
    Serial.print(cm);
    Serial.print("cm");
    Serial.println();

    delay(100);

  }
}

long microsecondsToInches(long microseconds)
{

  return microseconds / 74 / 2;
}

long microsecondsToCentimeters(long microseconds)
{

  return microseconds / 29 / 2;
}
Sketch uses 3,436 bytes (10%) of program storage space. Maximum is 32,256 bytes.
Global variables use 225 bytes (10%) of dynamic memory, leaving 1,823 bytes for local variables. Maximum is 2,048 bytes.

And those code 'blocks' can be made using code tags ( [code] and [/code] ).

I had downloaded the Arduino app through app store and that caused the errors. Thank you guys