Browse Source

Lesson 53

master
Tom Nordal 2 years ago
parent
commit
db26bc2b47
  1. 10
      Sensors/platformio.ini
  2. 17
      Sensors/src/main.cpp

10
Sensors/platformio.ini

@ -12,8 +12,8 @@
platform = atmelavr platform = atmelavr
board = uno board = uno
framework = arduino framework = arduino
lib_deps = ; lib_deps =
# RECOMMENDED ; # RECOMMENDED
# Accept new functionality in a backwards compatible manner and patches ; # Accept new functionality in a backwards compatible manner and patches
adafruit/DHT sensor library @ ^1.4.6 ; adafruit/DHT sensor library @ ^1.4.6
arduino-libraries/LiquidCrystal @ ^1.0.7 ; arduino-libraries/LiquidCrystal @ ^1.0.7

17
Sensors/src/main.cpp

@ -3,13 +3,26 @@
#include <Arduino.h> #include <Arduino.h>
int trigPin = 12;
int echoPin = 11;
int pingTravleTime;
void setup() { void setup() {
// put your setup code here, to run once: // put your setup code here, to run once:
Serial.begin(9600); Serial.begin(9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
} }
void loop() { void loop() {
// put your main code here, to run repeatedly: // put your main code here, to run repeatedly:
digitalWrite(trigPin, LOW);
delayMicroseconds(10);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
pingTravleTime = pulseIn(echoPin, HIGH);
delay(25);
Serial.print("Ping Time: ");
Serial.println(pingTravleTime);
} }

Loading…
Cancel
Save