• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ pulseIn函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中pulseIn函数的典型用法代码示例。如果您正苦于以下问题:C++ pulseIn函数的具体用法?C++ pulseIn怎么用?C++ pulseIn使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了pulseIn函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: pinMode

long MeUltrasonicSensor::measure(){
	long duration;
	pinMode(s2, OUTPUT);
	MeOutput::write1(0);
	delayMicroseconds(2);
	MeOutput::write1(1023);
	delayMicroseconds(10);
	MeOutput::write1(0);
	pinMode(s1,INPUT);
	duration = pulseIn(s1,HIGH);
	return duration;
}
开发者ID:JasenWang,项目名称:Makeblock-Library,代码行数:12,代码来源:Makeblock.cpp


示例2: digitalWrite

long Ultrasonic::getTimming()
{
	digitalWrite(trigger_pin, LOW); 
	delayMicroseconds(2); 

	digitalWrite(trigger_pin, HIGH);
	delayMicroseconds(10); 

	digitalWrite(trigger_pin, LOW);

	return pulseIn(echo_pin, HIGH, timeout);
}
开发者ID:MinervaBots,项目名称:Hound,代码行数:12,代码来源:ultrasonic.cpp


示例3: startPwm

///////////////////////
// Internal functions
///////////////////////
int Distance::checkModule(uint8_t module)
{
  long duration, distance;
  startPwm();
  setShift(module, PULSE_TIME);
  duration = pulseIn(ULTRASOUND_RECEIVE_PIN, HIGH);
  distance = (duration * CM_PER_MICROSECOND) + FIXED_OFFSET;
  //distance = (.13077*pow(duration,1-.2421));
  stopPwm();
  delay(250);
  return (int)distance;
}
开发者ID:kelliott121,项目名称:Udel_Skynet,代码行数:15,代码来源:Distance.cpp


示例4: digitalWrite

long Ultrasonic::Timing()
{
  digitalWrite(Trig_pin, LOW);
  delayMicroseconds(2);
  digitalWrite(Trig_pin, HIGH);
  delayMicroseconds(10);
  digitalWrite(Trig_pin, LOW);
  duration = pulseIn(Echo_pin,HIGH,Time_out);
  if ( duration == 0 ) {
	duration = Time_out; }
  return duration;
}
开发者ID:camiloaguilar91,项目名称:NeuroDrift,代码行数:12,代码来源:Ultrasonic.cpp


示例5: digitalWrite

ultrasonic::udistance()
{
    
       digitalWrite(trigPin,HIGH);
       delayMicroseconds(15);
       digitalWrite(trigPin,LOW);
       delayMicroseconds(2);
       duration = pulseIn(echoPin, HIGH);
       uldistance = duration/58.2;
       return uldistance;
    
}
开发者ID:renu285,项目名称:Arduino_Robot,代码行数:12,代码来源:arduinorobo.cpp


示例6: digitalWrite

// HC-SR04 ultrasonic sensor driver
unsigned int SonarControl::readHCSR04(int triggerPin, int echoPin){
  unsigned int uS;  
  digitalWrite(triggerPin, LOW); 
  delayMicroseconds(2); 
  digitalWrite(triggerPin, HIGH);
  delayMicroseconds(10); 
  digitalWrite(triggerPin, LOW);
  uS = pulseIn(echoPin, HIGH, MAX_ECHO_TIME + 1000);  
  if (uS > MAX_ECHO_TIME) uS = NO_ECHO;
    else if (uS < MIN_ECHO_TIME) uS = NO_ECHO;
  return uS;
}
开发者ID:fghorow,项目名称:ardumower,代码行数:13,代码来源:sonar.cpp


示例7: SonarTask

void SonarTask(void* p)
{

	float cmdistance_1; //left
	float cmdistance_2; //right
	long microsec = ultrasonic.timing(); //MODIFIED DELAY FUNCTION
	long microsec_2 = ultrasonic_2.timing();
	
	    digitalWrite(trigpin_1, LOW);
		digitalWrite(trigpin_2, LOW);
	    vTaskDelay(2);
	    digitalWrite(trigpin_1, HIGH);
		digitalWrite(trigpin_2, HIGH);
	    vTaskDelay(10);
	    digitalWrite(trigpin_1, LOW);
		digitalWrite(trigpin_2, LOW);
	    long microsec_1 = pulseIn(echopin_1, HIGH);
		long microsec_2 = pulseIn(echopin_2, HIGH);
	    cmdistance_1 = microsec_1 / cmdivisor / 2.0;
		cmdistance_2 = microsec_2 / cmdivisor / 2.0;
		
	    int distance_left = (int) cmdistance_1;
		int distance_right = (int) cmdistance_2;
		
		if(cmdistance>40 && cmdistance<60) {

		}
		else if (cmdistance<40)	{

		}
		else { }

		if(cmdistance>40 && cmdistance<60) {

		}
		else if (cmdistance<40)	{

		}
		else { }
}
开发者ID:Thearith,项目名称:cg3002py,代码行数:40,代码来源:SonarTask.cpp


示例8: pinMode

DHT11Result DHT11::read()
{
  pinMode(_pin, OUTPUT);
  digitalWrite(_pin, LOW);
  delay(20);

  uint32_t cycles[80];

  noInterrupts();
  {
    pinMode(_pin, INPUT_PULLUP);

    if (pulseIn(_pin, HIGH) == 0) {
      return prepareErrorResult("Timeout waiting for start signal LOW pulse");
    }

    for (int i = 0; i < 80; i+= 2) {
      cycles[i] = pulse(LOW, 150);
      cycles[i + 1] = pulse(HIGH, 150);
    }

    interrupts();
  }

  uint32_t data[5];
  data[0] = data[1] = data[2] = data[3] = data[4] = 0;

  for (int i = 0; i < 40; ++i) {
    uint32_t lowCycles  = cycles[2 * i];
    uint32_t highCycles = cycles[2 * i + 1];

    data[i/8] <<= 1;

    if (highCycles > lowCycles) {
      data[i/8] |= 1;
    }
  }

  uint32_t calculatedParity = (data[0] + data[1] + data[2] + data[3]) & 0xFF;

  if (data[4] != calculatedParity)
  {
    return prepareErrorResult("Parity check failed");
  }

  DHT11Result result;
  result.hasError = false;
  result.errorMessage = "";
  result.humidity = data[0];
  result.temperatureC = data[2];
  return result;
}
开发者ID:fduman,项目名称:dht11_esp8266,代码行数:52,代码来源:dht11sensor.cpp


示例9: loop

void loop() {
// establish variables for duration of the ping,
// and the distance result in inches and centimeters:
	long duration, inches, cm;

// The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
// Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
	pinMode(pingPin, OUTPUT);
	digitalWrite(pingPin, LOW);
	delayMicroseconds(2);
	digitalWrite(pingPin, HIGH);
	delayMicroseconds(10);
	digitalWrite(pingPin, LOW);

// The same pin is used to read the signal from the PING))): a HIGH
// pulse whose duration is the time (in microseconds) from the sending
// of the ping to the reception of its echo off of an object.
	pinMode(inPin, INPUT);
	duration = pulseIn(inPin, HIGH);

// convert the time into a distance
	inches = microsecondsToInches(duration);
	cm = microsecondsToCentimeters(duration);

	Serial.println(cm, DEC);

	if (cm < 3) {
		// play the note corresponding to this sensor:
		tone(8, notes[4], 30);
	}

	if ((cm >= 3) && (cm <= 9)) {
		// play the note corresponding to this sensor:
		tone(8, notes[0], 30);
	}

	if ((cm >= 10) && (cm <= 19)) {
		// play the note corresponding to this sensor:
		tone(8, notes[1], 30);
	}
	if ((cm >= 20) && (cm <= 29)) {
		// play the note corresponding to this sensor:
		tone(8, notes[2], 30);
	}

	if ((cm >= 30) && (cm <= 49)) {
		// play the note corresponding to this sensor:
		tone(8, notes[3], 30);
	}

	delay(100);
}
开发者ID:Blair79,项目名称:ArduinoMega,代码行数:52,代码来源:PingTone.cpp


示例10: sonar_loop

void sonar_loop()
{
  pinMode(pwPin, INPUT);
  pulse = pulseIn(pwPin, HIGH);
  inches = pulse / 147;
  cm = inches * 2.54;
  Serial.print(inches);
  Serial.print("in, ");
  Serial.print(cm);
  Serial.print("cm");
  Serial.println();
  delay(500);
}
开发者ID:karlzipser,项目名称:kzpy3.0,代码行数:13,代码来源:sonar_core.cpp


示例11: micros

float BlockingRC::getValueWithDelay(int pinIndex, long int delayInMicros)   //get the current RC reading for the channel 'pinIndex', provided that the time elapsed since the last reading was taken is greater than delayInMicros
{
	long int currentTime = micros();
	if((currentTime - lastReadTime)>delayInMicros)
	{
	lastReadTime = currentTime;
	return lastValue = pulseIn(pin[pinIndex], HIGH, 25000);
	}
	else
	{
	return lastValue;
	}
}
开发者ID:Lockdog88,项目名称:NoobCopter,代码行数:13,代码来源:BlockingRC.cpp


示例12: frontleftsensor

void frontleftsensor(){
  //———Front Left Sensor-------- 
  digitalWrite(trigPinFL, HIGH); //triggers sonar
  delayMicroseconds(1000);
  digitalWrite(trigPinFL, LOW); //turn off the sonar sender
  durationFL = pulseIn(echoPinFL, HIGH);//measures distance
  distanceFL = (durationFL/2) / 29.1; //converts to cm
 //Serial.print("distanceFL = ");
 //Serial.println(distanceFL);
  if (distanceFL<=10)
    frontleftsensor();
  delay(5);
}
开发者ID:KlaytonH,项目名称:Capstone_ECE_IV,代码行数:13,代码来源:delaytest.cpp


示例13: pulseIn

unsigned int Remote::measure(byte channel)
{
	unsigned int measurement;

	measurement = pulseIn(_pins[channel], HIGH, 6000); // 30000 for servo at 50Hz, 5500 at 300Hz
	
	if(_debug)
	{
		printUnsigned("Remote Measure: ", measurement);
	}

	return(measurement); 
}
开发者ID:LouisSR,项目名称:Arduino-Libraries,代码行数:13,代码来源:Remote.cpp


示例14: digitalWrite

unsigned long LUltrasonic::measureDistance() {
	unsigned long duration, distance; 

	digitalWrite(_triggerPin, LOW); 
	delayMicroseconds(10); 
	digitalWrite(_triggerPin, HIGH);
	delayMicroseconds(20);
	digitalWrite(_triggerPin, LOW);
	duration = pulseIn(_echoPin, HIGH);
	distance = duration / 29 / 2;
    
    return distance <= MAX_MEASUREABLE_DISTANCE ? distance : INFINITE_DISTANCE;
}
开发者ID:hmkwizu,项目名称:LRover,代码行数:13,代码来源:LUltrasonic.cpp


示例15: pinMode

long Me_UltrasonicSensor::measure()
{
	long duration;
	pinMode(signalPin, OUTPUT);
	digitalWrite(signalPin, LOW);
	delayMicroseconds(2);
	digitalWrite(signalPin, HIGH);
	delayMicroseconds(10);
	digitalWrite(signalPin,LOW);
	pinMode(signalPin,INPUT);
	duration = pulseIn(signalPin,HIGH);
	return duration;
}
开发者ID:nichtich,项目名称:Me_Lib,代码行数:13,代码来源:Me_UltrasonicSensor.cpp


示例16: get_distance

int get_distance(){
  //returns distance in centimeters from a ping sensor setup on pin 53
  pinMode(53, OUTPUT);
  digitalWrite(53, LOW);
  delayMicroseconds(2);
  digitalWrite(53, HIGH);
  delayMicroseconds(5);
  digitalWrite(53, LOW);

  pinMode(53, INPUT);

  return pulseIn(53, HIGH) / 29 / 2;
}
开发者ID:mschuldt,项目名称:maml,代码行数:13,代码来源:arduino_only_primitives.c


示例17: delayMicroseconds

/**
 * \par Function
 *   measure
 * \par Description
 *   To get the duration of the ultrasonic sensor
 * \param[in]
 *   timeout - This value is used to define the measurement range, The
 *   default value is 30000.
 * \par Output
 *   None
 * \return
 *   The duration value associated with distance
 * \par Others
 *   None
 */
long MeUltrasonicSensor::measure(unsigned long timeout)
{
  long duration;
  MePort::dWrite2(LOW);
  delayMicroseconds(2);
  MePort::dWrite2(HIGH);
  delayMicroseconds(10);
  MePort::dWrite2(LOW);
  pinMode(s2, INPUT);
  duration = pulseIn(s2, HIGH, timeout);
  delayMicroseconds(200);
  return(duration);
}
开发者ID:9ins,项目名称:Makeblock-Libraries,代码行数:28,代码来源:MeUltrasonicSensor.cpp


示例18: pulse

    long pulse(int mode, double timeout = 5) {
        if(pin == NULL) {
            puts("Pin not initialized!");
            return 0;
        }
        if(this->mode == OUTPUT){
            //muxPin(pin, 0x27);
            digitalMode(pin, INPUT);
            this->mode = INPUT;
        }

        return pulseIn(pin, mode, timeout);
    }
开发者ID:NickPablo,项目名称:BBLIB,代码行数:13,代码来源:DigitalPin.hpp


示例19: pinMode

int UltrasonicSensor::getDistance(){
	pinMode(trig, OUTPUT);
	digitalWrite(trig,LOW);
	delayMicroseconds(2);
	digitalWrite(trig, HIGH);
	delayMicroseconds(5);
	digitalWrite(trig, LOW);
	
	pinMode(echo, INPUT);
	int duration = pulseIn(echo, HIGH,11800);
	int distance = duration/29/2;
	
	return distance;
}
开发者ID:aloaisa,项目名称:BasicEducationShield,代码行数:14,代码来源:UltrasonicSensor.cpp


示例20: millis

bool LeWeiPPDSensor::getValue(double *i)
{
    const unsigned long sampletime_ms = 30000;
    unsigned long lowpulseoccupancy = 0;

    unsigned long stoptime = millis() + sampletime_ms;
    while (((signed long)millis() - (signed long)stoptime) < 0)
        lowpulseoccupancy += pulseIn(_pin, LOW);

    float ratio = lowpulseoccupancy/(sampletime_ms*10.0);  // Integer percentage 0=>100
    *i = 1.1*pow(ratio,3)-3.8*pow(ratio,2)+520*ratio+0.62; // using spec sheet curve

    return true;
}
开发者ID:Inhighway,项目名称:LeweiClient,代码行数:14,代码来源:LeweiDevice.cpp



注:本文中的pulseIn函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ purple_account_get_connection函数代码示例发布时间:2022-05-30
下一篇:
C++ pulseEnable函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap