From c11fc035db6031a6d1e5d1ed7a236ad5ee35484f Mon Sep 17 00:00:00 2001 From: Stefan Date: Tue, 3 May 2022 22:19:00 +0200 Subject: [PATCH] =?UTF-8?q?Grundfunktion=20f=C3=BCr=20Ultraschallsensor=20?= =?UTF-8?q?und=20LED=20Licht?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Abstandssensor.ino | 107 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 Abstandssensor.ino diff --git a/Abstandssensor.ino b/Abstandssensor.ino new file mode 100644 index 0000000..2b1bba4 --- /dev/null +++ b/Abstandssensor.ino @@ -0,0 +1,107 @@ +#include +#include +#include +#include + + +// DEV or PROD Setup +#define DEBUG + +// Only for ESP8266 D1 Mini +#define ECHO 5 // D1 +#define TRIG 16 // D0 +#define POTI_IN 17 // A0, analog In + +#define DATA_PIN 3 +const uint16_t PixelCount = 8; +NeoPixelBus strip(PixelCount, DATA_PIN); + +long duration; // Variable um die Zeit der Ultraschall-Wellen zu speichern +float distance; // Variable um die Entfernung zu berechnen + +int poti; +int percent=0; +int colorSaturation=255; + +RgbColor red(colorSaturation, 0, 0); +RgbColor green(0, colorSaturation, 0); +RgbColor yellow(colorSaturation, colorSaturation, 0); +RgbColor blue(0, 0, colorSaturation); +RgbColor white(colorSaturation); +RgbColor black(0); + +void setup() { + + pinMode(TRIG, OUTPUT); // TRIG-Pin: Output + pinMode(ECHO, INPUT); // ECHO-Pin: Input + + #ifdef DEBUG + Serial.begin(9600); // Baudrate: 115200 + #endif + + // this resets all the neopixels to an off state + strip.Begin(); + for(int i=0; i150) { setGreen(); } + else if (percent >100) { setYellow(); } + else {setRed(); } + + // Anzeige der Entfernung im seriellen Monitor + #ifdef DEBUG + Serial.println("Poti: " + String(poti)); + Serial.println("Entfernung: " + String(distance) + "cm"); + Serial.println("Percent: " + String(percent) + " of goal value"); + #endif + delay(100); + +}