Arduino ide
Napsal: 23 bře 2021, 12:25
LiquidCrystal sensor anemometer arduino
České fórum pro všechny nadšence do Arduina a dalších technologií.
https://forum.hwkitchen.cz/
Kód: Vybrat vše
//More Information at: https://www.aeq-web.com/
//Version 2.0 | 11-NOV-2020
#include <LiquidCrystal.h>
const int rs = 12, en = 11, d4 = 7, d5 = 6, d6 = 5, d7 = 4;
//Zapojenie dátových vodičov
//Displej ==> Arduino
//RS ==> D12
//RN ==> D11
//D4 ==> D7
//D5 ==> D6
//D6 ==> D5
//D7 ==> D4
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
const int RecordTime = 3; //Define Measuring Time (Seconds)
const int SensorPin = 3; //Define Interrupt Pin (2 or 3 @ Arduino Uno)
int InterruptCounter;
float WindSpeed;
void setup()
{
Serial.begin(9600);
lcd.begin(16, 2); //rozmer displeja 16x2, možne nahradiť za 20x4 --> PROGRAM POUZIVA 16 stlpcov a 2 riadky!!!
}
void loop() {
meassure();
Serial.print(F("Wind Speed: "));
Serial.print(WindSpeed); //Speed in km/h
Serial.print(F(" km/h - "));
Serial.print(WindSpeed / 3.6); //Speed in m/s
Serial.println(F(" m/s"));
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(WindSpeed); //Speed in km/h
lcd.print(F(" km/h"));
lcd.setCursor(0, 1);
lcd.print(WindSpeed / 3.6); //Speed in m/s
lcd.print(F(" m/s"));
}
void meassure() {
InterruptCounter = 0;
attachInterrupt(digitalPinToInterrupt(SensorPin), countup, RISING);
delay(1000 * RecordTime);
detachInterrupt(digitalPinToInterrupt(SensorPin));
WindSpeed = (float)InterruptCounter / (float)RecordTime * 2.4;
}
void countup() {
InterruptCounter++;
}
Proti principu měření se ohradím (ale spíše jako vylepšení třeba do budoucna - já to takto také zatím provozuji).