Servo.h: mudanças entre as edições

De IFSC
Ir para navegação Ir para pesquisar
imported>Fargoud
Sem resumo de edição
imported>Fargoud
Sem resumo de edição
 
Linha 90: Linha 90:




Outro exemplo:


#include "SR04.h"
#define TRIG_PIN 12
#define ECHO_PIN 11
SR04 sr04 = SR04(ECHO_PIN,TRIG_PIN);
long a;
void setup() {
    Serial.begin(9600);
    delay(1000);
}
void loop() {
    a=sr04.Distance();
    Serial.print(a);
    Serial.println("cm");
    delay(1000);
}


#######################################
# Syntax Coloring Map SR04 lib
#######################################
#######################################
# Datatypes (KEYWORD1)
#######################################


#######################################
# Syntax Coloring Map SR04 lib
#######################################
#######################################
# Datatypes (KEYWORD1)
#######################################
  #######################################
  #######################################
  # Methods and Functions (KEYWORD2)
  # Methods and Functions (KEYWORD2)

Edição atual tal como às 15h25min de 8 de maio de 2019

#ifndef SR04_H
#define SR04_H

#if defined(ARDUINO) && ARDUINO >= 100
   #include "Arduino.h"
#else
   #include "WProgram.h"
#endif
 //#include "pins_arduino.h"
 
#include <inttypes.h>

#define PULSE_TIMEOUT 150000L	// 100ms
#define DEFAULT_DELAY 10
#define DEFAULT_PINGS 5
class SR04 {
public:

/**
* Constructor
* Ultrasonic sensor SR04, four connections pins
* VCC, ECHO, TRIGGER, GND
* 
* \param echoPin digital INPUT-Pin for measuring distance * \param triggerPin if 10us high a trigger signal is generated from * SR04 * * \return void */ SR04(int echoPin, int triggerPin); /** * Do a measurment for this sensor. Return distance as long * in centimenter * \return long distance in centimeter */ long Distance(); /** * Do count measurents and calculate the average. * To avoid defilement from ow/high peaks, min/max values * are substracted from the average * * \param wait delay between measurements, default = DEFAULT_DELAY/ms * \param count number of measurements, default DEFAULT_PINGS * \return long distance in centimeter **/ long DistanceAvg(int wait=DEFAULT_DELAY, int count=DEFAULT_PINGS); /** * Do only a ping. Get result with methode getDistance() * * \param keine */ void Ping() ; /** * return latest distance. Methode Ping() should be called before * \param keine * \return Distanz in Zentimeter */ long getDistance(); private: /** * Do the measurement calculation and return result in centimeter * SR04 measure echo time to obstacle and return way. *
* Sound travels with 340m/sec *
* Example: Obstace 100cm away from SR04. Measure time is 100cm to * obstacle and 100cm return = 200cm *
* 1sec = 1000ms = 1.000.000uS * 1.000.000 / 340 = Distance in microseconds for 100cm * 2941uS fuer 100cm = 5882 uS fuer 200cm * * duration / 5882 * 100 = distance in cm */ long MicrosecondsToCentimeter(long duration); long _currentDistance; int _echoPin, _triggerPin; long _duration, _distance; bool _autoMode; }; #endif


Outro exemplo:

#include "SR04.h"
#define TRIG_PIN 12
#define ECHO_PIN 11
SR04 sr04 = SR04(ECHO_PIN,TRIG_PIN);
long a;

void setup() {
   Serial.begin(9600);
   delay(1000);
}

void loop() {
   a=sr04.Distance();
   Serial.print(a);
   Serial.println("cm");
   delay(1000);
}


#######################################
#	Syntax	Coloring	Map	SR04	lib
#######################################

#######################################
#	Datatypes	(KEYWORD1)
#######################################

#######################################
#	Methods	and	Functions	(KEYWORD2)
####################################### 
Distance	KEYWORD2	Distance
DistanceAvg	KEYWORD2	Distance average
Ping	KEYWORD2	only a ping signal
getDistance	KEYWORD2	get distance after ping

#######################################
#	Instances	(KEYWORD2)
#######################################
SR04	KEYWORD2	ultrasonic library

#######################################
#	Constants	(LITERAL1)
#######################################