millisec help


hi guys. got ultrasonic sensor(parallax) , led. want power ultrasonic sensor according ledstate exit status 1 , stray \302 error. me plzz. here code

const int pingpin = 7;
int ledpin =  13;      // number of led pin
int ledstate = low;             // ledstate used set led
unsigned long previousmillis = 0;        // store last time led 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 see if it's time change state of led
  unsigned long currentmillis = millis();
  long duration, inches, cm;
 
  if((ledstate == high) && (currentmillis - previousmillis >= ontime))
  {
    ledstate = low;  // turn off
    previousmillis = currentmillis;  // remember time
    digitalwrite(ledpin, ledstate);  // update actual led
  }
  else if ((ledstate == low) && (currentmillis - previousmillis >= offtime))
  {
    ledstate = high;  // turn on
    previousmillis = currentmillis;   // remember time
    digitalwrite(ledpin, ledstate);    // update 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 compiled code improperly posted, got:
quote
sketch uses 3,982 bytes (1%) of program storage space. maximum 253,952 bytes.
global variables use 224 bytes (2%) of dynamic memory, leaving 7,968 bytes local variables. maximum 8,192 bytes.
that result people strive for.

if got different results, post of error messages, along board compiling , version of ide using , os using.

you aren't stuck in xp stone ages, you?


Arduino Forum > Using Arduino > Programming Questions > millisec help


arduino

Comments

Popular posts from this blog

DHT11 Time out error using v0.4.1library

Sketch upload fails with Java error (___REMOVE___/bin/avrdude)!

Arduino Uno + KTY81/210 temperature sensor