1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292
| #define LCD_WIDTH 20
// lignes (179,175,171,167,163,159) réglage des différentes alertes
// Anzahl Zeilen des Display (4)
#define LCD_HEIGHT 4
// Pin capteur effet hall
#define REEDPIN 2// PIN D2
// Interruptions matérielles pour le Reed-Pin
#define REEDINTERRUPT 0 //PIN A0
// Umfang in mm wurde im Windkanal mit dem Volkswindmesser ermittelt als Referenz
#define RADUMFANG 2200
// LED Balken
#define led05 11 // LED connected to digital pin 11
#define led10 10 // LED connected to digital pin 10
#define led15 9 // LED connected to digital pin 9
#define led20 8 // LED connected to digital pin 8
#define led25 7 // LED connected to digital pin 7
#define led30 6 // LED connected to digital pin 6
#define ledalarm 13 // LED ALARM
#define resetmaxpin 3 // remise a zero max Pin (button)
#define resetalarmpin 4 // remise a zero Alarm Pin (button)
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4);//SCL A5 SDA A 4
int LDR_pin = A1;
int back_light = 10;
int led = 5; //PIN SORTIE RETROECLAIRAGE LCD
int LDR_out;
int pwm_back_light;
int pwm_led;
void setup(){
lcd.begin(16,2);
lcd.init();
lcd.backlight(); // Allume le retroeclairage
pinMode(LDR_pin,INPUT);
pinMode(back_light,OUTPUT);
pinMode(led,OUTPUT);
lcd.setCursor ( 0, 0 ); // erste Zeile mit Alarm
lcd.print ("Anemometre Pergola");
lcd.setCursor ( 0, 1 ); // zweite Zeile
lcd.print ("Reglage alarme");
//Switch on the backlight
//pinMode ( BACKLIGHT_PIN, OUTPUT );
//digitalWrite ( BACKLIGHT_PIN, HIGH );
pinMode(REEDPIN, INPUT_PULLUP); // Reedkontakt direkt und ohne Widerstand angeschlossen
attachInterrupt(REEDINTERRUPT, reedISR, FALLING);
Serial.begin(115200);
pinMode(led05, OUTPUT);
pinMode(led10, OUTPUT);
pinMode(led15, OUTPUT);
pinMode(led20, OUTPUT);
pinMode(led25, OUTPUT);
pinMode(led30, OUTPUT);
pinMode(resetmaxpin, INPUT_PULLUP); // Resetmax Taster direkt und ohne Widerstand angeschlossen (gegen ground)
pinMode(resetalarmpin, INPUT_PULLUP); // Resetalarm Taster direkt und ohne Widerstand angeschlossen (gegen ground)
}
float ms2; //globale Variable Speed in m/s
float msmax = 0; //Maximalwert
unsigned long umin; // U/min
int alarm; // Alarmgrenze in m/s (meter/sekunde)
volatile byte reedCountSum;
volatile long reedMillisSum;
unsigned long lastReedMillis;
void reedISR()
{
if (millis()-lastReedMillis>=5) // 25ms entspricht max. 40 Umdrehungen pro Sekunde (bei Volkswindmesser reichen 2ms Entprellzeit aus)
{
reedCountSum++; // eine Radumdrehung zählen
reedMillisSum+=millis()-lastReedMillis; // Zeit addieren
lastReedMillis=millis(); // Zeit merken
}
}
unsigned long gesamtUmdrehungen = 0; //4545300;
void tachoAnzeige()
{
byte umdrehungen;
unsigned long zeit;
float kph, kilometer, ms;
char buffer[10];
noInterrupts(); // Interrupts sperren
umdrehungen=reedCountSum;// Zählvariable umkopieren
reedCountSum=0; // Zählvariable auf 0 zurücksetzen
zeit=reedMillisSum; // Zeitzähler umkopieren
reedMillisSum=0; // Zeitzähler auf 0 zurücksetzen
interrupts(); // Interrupts wieder zulassen
gesamtUmdrehungen+= umdrehungen; // Aufsummieren aller Radumdrehungen
kilometer=(float)gesamtUmdrehungen*(float)RADUMFANG/1000000.0; // Kilometerzähler
if (umdrehungen>0){
kph=float(RADUMFANG)*(float)umdrehungen/(float)zeit*3.6;
ms=float(RADUMFANG)*(float)umdrehungen/(float)zeit;
umin=umdrehungen*60000/zeit; }
else {
kph=0.0; //Null setzen wenn keine Umdrehung gefunden wurde
umin = 0; } //Null setzen wenn keine Umdrehung gefunden wurde
// ms = kph/3.6; //aus km/h mach m/s - kmh/3.6
ms2 = ms; //variable ms in ms2 global kopieren
//LCD Ausgabe -- Kilometerzähler hier deaktiviert
//lcd.setCursor(0, 2);
//dtostrf(kilometer,8,3,buffer);
//lcd.print(buffer);
//Serial.println(buffer);
//lcd.print(" km MAX:");
//dtostrf(msmax,4,1,buffer);
//lcd.print(buffer);
// Serial.println(buffer);
//LCD Ausgabe -- U/min und Maximalwert
lcd.setCursor(0, 2);
sprintf(buffer,"%4i U/min ",umin); // mit Nullen - sprintf(buffer,"%04i U/min ",umin); 4-Stellen Lagerichtig :-).
lcd.print(buffer);
dtostrf(msmax,5,2,buffer); // Insgesamt 5 Stellen 12.45 (Dezimalpunkt ist auch eine Stelle)
lcd.print(buffer);
lcd.print(" MAX");
//LCD Ausgabe -- km/h
lcd.setCursor(0, 3);
dtostrf(kph,5,1,buffer);
lcd.print(buffer);
// Serial.println(buffer);
lcd.setCursor(5, 3);
lcd.print(" km/h ");
//LCD Ausgabe -- m/s
dtostrf(ms,5,2,buffer);
lcd.print(buffer);
// Serial.println(buffer);
lcd.setCursor(16, 3);
lcd.print(" m/s");
//maximal mémorisées
if (ms2 > msmax) {
msmax = ms2; }
// Serial.println(msmax);
//umin 0 setzen wenn ms2 0 ist.
// if (ms2 == 0.0) {
// umin = 0; }
//Serial.println(gesamtUmdrehungen);
//Commande des barres LED
if (kph >= 5) {
digitalWrite(led05, HIGH); }
else {
digitalWrite(led05, LOW); }
if (kph >= 10) {
digitalWrite(led10, HIGH); }
else {
digitalWrite(led10, LOW); }
if (kph >= 15) {
digitalWrite(led15, HIGH); }
else {
digitalWrite(led15, LOW); }
if (kph >= 20) {
digitalWrite(led20, HIGH); }
else {
digitalWrite(led20, LOW); }
if (kph >= 25) {
digitalWrite(led25, HIGH); }
else {
digitalWrite(led25, LOW); }
if (kph >= 165) {
digitalWrite(led30, HIGH); }
else {
digitalWrite(led30, LOW); }
}
unsigned long interval; // update LCD/LED interval (milliseconds)
unsigned long previousMillis = 0;
unsigned long intervalalarm = 200; // update Alarm Anzeige interval (milliseconds)
unsigned long previousMillisalarm = 0;
unsigned long currentMillis;
int potpin = 2; // A0 broche analogique utilisée pour connecter le potentiomètre
int val; // variable pour lire la valeur à partir de la broche analogique
void loop()
{
//Adapter lentrée dévaluation en fonction du régime
if (ms2 < 1) {
interval = 4000; }
if (ms2 >= 1 && ms2 < 2) {
interval = 2100; }
if (ms2 >= 2 && ms2 < 3) {
interval = 1100; }
if (ms2 >= 3 && ms2 < 4) {
interval = 800; }
if (ms2 >= 4 && ms2 < 6 ) {
interval = 600; }
if (ms2 > 6) {
interval = 400; }
// Anzeige wird nach dem eingestellten inteval aktualisiert
currentMillis = millis();
if (currentMillis - previousMillis >= interval)
{
tachoAnzeige();
previousMillis = currentMillis;
}
// Alaramzeige wird nach dem eingestellten interval aktualisiert
if (currentMillis - previousMillisalarm >= intervalalarm)
{
val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
alarm = map(val, 0, 1023, 0, 30); // scalieren der Potistellung (0-30m/s)
lcd.setCursor(18, 1);
if(alarm < 10) lcd.print("0"); // ein leerzeichen oder auch Zahl Nullf(zahl <10) print(" "); // ein leerzeichen oder auch Zahl Null
lcd.print(alarm);
//Alarm LED einschalten wenn Wind > Alarmwert
if (ms2 > alarm) {
digitalWrite(ledalarm, HIGH);
lcd.setCursor(0, 1);
lcd.print("**** A L A R M ****"); }
previousMillisalarm = currentMillis;
}
// Alarm LED zurücksetzen wenn Wind >5ms oder resetbutton gedrückt wird
// if (ms2 < 2 && digitalRead(ledalarm) == HIGH || digitalRead(resetmaxpin) == LOW)
if (digitalRead(resetalarmpin) == LOW) {
digitalWrite(ledalarm, LOW);
lcd.setCursor(0, 1);
lcd.print (" Remise a zero");
}
//Suppression des 10 premières rotations ou réinitialisation du bouton pour rétablir la valeur maximale
if (gesamtUmdrehungen < 10 || digitalRead(resetmaxpin) == LOW ) {
msmax = 0; }
//gesamtUmdrehungen resetten bevor Display überlauf
if (gesamtUmdrehungen > 4545430) {
gesamtUmdrehungen = 0; }
{
LDR_out = analogRead (LDR_pin);
pwm_led = LDR_out / 5;
pwm_back_light = 255- (LDR_out / 5);
Serial.println (pwm_back_light);
analogWrite (back_light, pwm_back_light);
analogWrite (led, pwm_led);
delay(1000);
}
}
//char buffer[7];
//sprintf(buffer,"%4imA",zahl);
//print buffer;
//mit Nullen
//char buffer[7];
//sprintf(buffer,"%04imA",zahl);
//print buffer; |