problem taking delay out of ping code
hey all,
i'm trying replace delay in ping sensor example code timer delay can have other things running @ same time.
i getting hung in attempts , new this. here code have far
i getting error
sketch_jun02b:28: error: expected unqualified-id before numeric constant
sketch_jun02b:36: error: expected ',' or ';' before 'void'
sketch_jun02b.ino: in function 'void loop()':
sketch_jun02b:54: error: lvalue required left operand of assignment
sketch_jun02b:58: error: lvalue required left operand of assignment
sketch_jun02b:62: error: lvalue required left operand of assignment
sketch_jun02b:84: error: lvalue required left operand of assignment
any appreciated. thanks
i'm trying replace delay in ping sensor example code timer delay can have other things running @ same time.
i getting hung in attempts , new this. here code have far
code: [select]
/* ping))) sensor
this sketch reads ping))) ultrasonic rangefinder , returns the
distance closest object in range. this, sends pulse
to sensor initiate reading, listens pulse
to return. length of returning pulse proportional
the distance of object sensor.
the circuit:
* +v connection of ping))) attached +5v
* gnd connection of ping))) attached ground
* sig connection of ping))) attached digital pin 7
http://www.arduino.cc/en/tutorial/ping
created 3 nov 2008
by david a. mellis
modified 30 aug 2011
by tom igoe
this example code in public domain.
*/
// constant won't change. it's pin number
// of sensor's output:
const int pingpin = 7;
//timer
long previousepingtimer = 0;
long pingpausetwo = 2;
long pingpausefive = 5;
long pingpauselong = 100;
long initialtimer=0
void setup() {
// initialize serial communication:
serial.begin(9600);
}
void loop()
{
unsigned long currentmillis = millis(); //start timer
// establish variables duration of ping,
// , distance result in inches , centimeters:
long duration, inches, cm;
// ping))) triggered high pulse of 2 or more microseconds.
// give short low pulse beforehand ensure clean high pulse:
pinmode(pingpin, output);
if(currentmillis - previousepingtimer = initialtimer)
{
digitalwrite(pingpin, low);
}
if(currentmillis - previousepingtimer = pingpausetwo)
{
digitalwrite(pingpin, high);
}
if(currentmillis - previousepingtimer - pingpausetwo = pingpausefive)
{
digitalwrite(pingpin, low);
// same pin used read signal ping))): high
// pulse duration time (in microseconds) sending
// of ping reception of echo off of object.
pinmode(pingpin, input);
duration = pulsein(pingpin, high);
// convert time distance
inches = microsecondstoinches(duration);
cm = microsecondstocentimeters(duration);
serial.print(inches);
serial.print("in, ");
serial.print(cm);
serial.print("cm");
serial.println();
}
if(currentmillis - previousepingtimer - pingpausetwo - pingpausefive = pingpauselong)
{
previousepingtimer = currentmillis;
}
}
long microsecondstoinches(long microseconds)
{
// according parallax's datasheet ping))), there are
// 73.746 microseconds per inch (i.e. sound travels @ 1130 feet per
// second). gives distance travelled ping, outbound
// , return, divide 2 distance of obstacle.
// see: http://www.parallax.com/dl/docs/prod/acc/28015-ping-v1.3.pdf
return microseconds / 74 / 2;
}
long microsecondstocentimeters(long microseconds)
{
// speed of sound 340 m/s or 29 microseconds per centimeter.
// ping travels out , back, find distance of the
// object take half of distance travelled.
return microseconds / 29 / 2;
}
i getting error
sketch_jun02b:28: error: expected unqualified-id before numeric constant
sketch_jun02b:36: error: expected ',' or ';' before 'void'
sketch_jun02b.ino: in function 'void loop()':
sketch_jun02b:54: error: lvalue required left operand of assignment
sketch_jun02b:58: error: lvalue required left operand of assignment
sketch_jun02b:62: error: lvalue required left operand of assignment
sketch_jun02b:84: error: lvalue required left operand of assignment
any appreciated. thanks
if(currentmillis - previousepingtimer = initialtimer) >>>>>>> if(currentmillis - previousepingtimer == initialtimer)
Arduino Forum > Using Arduino > Programming Questions > problem taking delay out of ping code
arduino
Comments
Post a Comment