parent
977d14f5a2
commit
2676c3f1c5
@ -0,0 +1,21 @@
|
|||||||
|
#include "TFT_eSPI.h"
|
||||||
|
TFT_eSPI tft;
|
||||||
|
|
||||||
|
// int tabPieces[4][2]={{4, 35}, {2, 15}, {100, 5}, {45, 120}, {90, 100}};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
tft.begin();
|
||||||
|
tft.setRotation(3); // (0,0) à l'oppossé du joyssitck
|
||||||
|
tft.fillScreen(TFT_WHITE); // fond blanc
|
||||||
|
|
||||||
|
pinMode(WIO_5S_UP, INPUT_PULLUP);
|
||||||
|
pinMode(WIO_5S_DOWN, INPUT_PULLUP);
|
||||||
|
pinMode(WIO_5S_LEFT, INPUT_PULLUP);
|
||||||
|
pinMode(WIO_5S_RIGHT, INPUT_PULLUP);
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
|
||||||
|
}
|
@ -1,58 +1,58 @@
|
|||||||
#include "Arduino.h"
|
// #include "Arduino.h"
|
||||||
class Ultrasonic
|
// class Ultrasonic
|
||||||
{
|
// {
|
||||||
public:
|
// public:
|
||||||
Ultrasonic(int pin);
|
// Ultrasonic(int pin);
|
||||||
void DistanceMeasure(void);
|
// void DistanceMeasure(void);
|
||||||
double microsecondsToCentimeters(void);
|
// double microsecondsToCentimeters(void);
|
||||||
double microsecondsToInches(void);
|
// double microsecondsToInches(void);
|
||||||
private:
|
// private:
|
||||||
int this_pin;//pin number of Arduino that is connected with SIG pin of Ultrasonic Ranger.
|
// int this_pin;//pin number of Arduino that is connected with SIG pin of Ultrasonic Ranger.
|
||||||
long duration;// the Pulse time received;
|
// long duration;// the Pulse time received;
|
||||||
};
|
// };
|
||||||
Ultrasonic::Ultrasonic(int pin)
|
// Ultrasonic::Ultrasonic(int pin)
|
||||||
{
|
// {
|
||||||
this_pin = pin;
|
// this_pin = pin;
|
||||||
}
|
// }
|
||||||
/*Begin the detection and get the pulse back signal*/
|
// /*Begin the detection and get the pulse back signal*/
|
||||||
void Ultrasonic::DistanceMeasure(void)
|
// void Ultrasonic::DistanceMeasure(void)
|
||||||
{
|
// {
|
||||||
pinMode(this_pin, OUTPUT);
|
// pinMode(this_pin, OUTPUT);
|
||||||
digitalWrite(this_pin, LOW);
|
// digitalWrite(this_pin, LOW);
|
||||||
delayMicroseconds(2);
|
// delayMicroseconds(2);
|
||||||
digitalWrite(this_pin, HIGH);
|
// digitalWrite(this_pin, HIGH);
|
||||||
delayMicroseconds(5);
|
// delayMicroseconds(5);
|
||||||
digitalWrite(this_pin,LOW);
|
// digitalWrite(this_pin,LOW);
|
||||||
pinMode(this_pin,INPUT);
|
// pinMode(this_pin,INPUT);
|
||||||
duration = pulseIn(this_pin,HIGH);
|
// duration = pulseIn(this_pin,HIGH);
|
||||||
}
|
// }
|
||||||
/*The measured distance from the range 0 to 400 Centimeters*/
|
// /*The measured distance from the range 0 to 400 Centimeters*/
|
||||||
double Ultrasonic::microsecondsToCentimeters(void)
|
// double Ultrasonic::microsecondsToCentimeters(void)
|
||||||
{
|
// {
|
||||||
return duration/29.0/2.0;
|
// return duration/29.0/2.0;
|
||||||
}
|
// }
|
||||||
/*The measured distance from the range 0 to 157 Inches*/
|
// /*The measured distance from the range 0 to 157 Inches*/
|
||||||
double Ultrasonic::microsecondsToInches(void)
|
// double Ultrasonic::microsecondsToInches(void)
|
||||||
{
|
// {
|
||||||
return duration/74.0/2.0;
|
// return duration/74.0/2.0;
|
||||||
}
|
// }
|
||||||
|
|
||||||
Ultrasonic ultrasonic(2);
|
// Ultrasonic ultrasonic(2);
|
||||||
void setup()
|
// void setup()
|
||||||
{
|
// {
|
||||||
Serial.begin(9600);
|
// Serial.begin(9600);
|
||||||
}
|
// }
|
||||||
void loop()
|
// void loop()
|
||||||
{
|
// {
|
||||||
double RangeInInches;
|
// double RangeInInches;
|
||||||
double RangeInCentimeters;
|
// double RangeInCentimeters;
|
||||||
ultrasonic.DistanceMeasure();// get the current signal time;
|
// ultrasonic.DistanceMeasure();// get the current signal time;
|
||||||
RangeInInches = ultrasonic.microsecondsToInches();//convert the time to inches;
|
// RangeInInches = ultrasonic.microsecondsToInches();//convert the time to inches;
|
||||||
RangeInCentimeters = ultrasonic.microsecondsToCentimeters();//convert the time to centimeters
|
// RangeInCentimeters = ultrasonic.microsecondsToCentimeters();//convert the time to centimeters
|
||||||
Serial.println("The distance to obstacles in front is: ");
|
// Serial.println("The distance to obstacles in front is: ");
|
||||||
Serial.print(RangeInInches);//0~157 inches
|
// Serial.print(RangeInInches);//0~157 inches
|
||||||
Serial.println(" inch");
|
// Serial.println(" inch");
|
||||||
Serial.print(RangeInCentimeters);//0~400cm
|
// Serial.print(RangeInCentimeters);//0~400cm
|
||||||
Serial.println(" cm");
|
// Serial.println(" cm");
|
||||||
delay(1000);
|
// delay(1000);
|
||||||
}
|
// }
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in new issue