microcontroller:wheel
//PINS #define REEDSWITCH 13 #define WHEELSIZE 0.91 volatile unsigned long rotations = 0; float meter = 0.0; volatile unsigned long lastactive = 0; // Debounce Vars volatile unsigned long last_micros; unsigned long debouncing_time = 500; //Debouncing Time in Milliseconds void setup() { // Reed Sensor (Interrupt) attachInterrupt(digitalPinToInterrupt(REEDSWITCH), debounceInterrupt, FALLING); //PINS pinMode(REEDSWITCH, INPUT); lastactive = millis(); } void loop() { if ( rotations >= 1 && ((millis() - lastactive) >= 1500) ) { meter = rotations * WHEELSIZE; // rotations = 0; // meter = 0; } } // ----- Helper Functions void debounceInterrupt() { if ( micros() < last_micros ) { last_micros = micros(); } if ((unsigned long)(micros() - last_micros) >= debouncing_time * 1000) { rotations++; last_micros = micros(); lastactive = millis(); } } #include "DHTesp.h" DHTesp dht; void setup() { Serial.begin(115200); Serial.println(); Serial.println("Status\tHumidity (%)\tTemperature (C)\t(F)\tHeatIndex (C)\t(F)"); dht.setup(12); // data pin 2 } void loop() { delay(dht.getMinimumSamplingPeriod()); float humidity = dht.getHumidity(); float temperature = dht.getTemperature(); Serial.print(dht.getStatusString()); Serial.print("\t"); Serial.print(humidity, 1); Serial.print("\t\t"); Serial.print(temperature, 1); Serial.print("\t\t"); Serial.print(dht.toFahrenheit(temperature), 1); Serial.print("\t\t"); Serial.print(dht.computeHeatIndex(temperature, humidity, false), 1); Serial.print("\t\t"); Serial.println(dht.computeHeatIndex(dht.toFahrenheit(temperature), humidity, true), 1); } #include < ESP8266WiFi.h> #include < WiFiClient.h> #include < ESP8266WebServer.h> // Replace with your network credentials const char* ssid = "Your WiFI SSID"; const char* password = "Your WiFI Password"; ESP8266WebServer server(80); //instantiate server at port 80 (http port) String page = ""; void setup(void){ delay(1000); Serial.begin(115200); WiFi.begin(ssid, password); //begin WiFi connection Serial.println(""); // Wait for connection while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(""); Serial.print("Connected to "); Serial.println(ssid); Serial.print("IP address: "); Serial.println(WiFi.localIP()); server.on("/", [](){ page = "ESP8266 Webserver - hello world!"; server.send(200, "text/html", page); }); server.begin(); Serial.println("Web server started!"); } void loop(void){ server.handleClient(); }
microcontroller/wheel.txt · Last modified: 2022/03/03 11:37 by illu