#include OneButton wind_speed_pulse(A0, true); //library is te vinden op http://www.mathertel.de/Arduino/OneButtonLibrary.aspx double bearing, WindBearing, ref = 512, //reference (180degrees) was 380 sinus = 0, cosinus = 0, LastWindSpeed = 0, a = 0, previousPulseMillis = millis(), speedCompensation = 0; unsigned long previousMillis_T1 = 0,previousMillis_T2 = 0; String NMEAsentence = ""; void setup() { Serial.begin(9600); wind_speed_pulse.setClickTicks(10); wind_speed_pulse.attachClick(calc_wind_speed); } void loop() { getSettings(); wind_speed_pulse.tick(); // check if wind sensor is activated get_WindBearing(); if(millis() - previousMillis_T2 >= 500) { if (a == LastWindSpeed) LastWindSpeed = 0; previousMillis_T2 = millis(); /* 1 2 3 4 5 | | | | | $--MWV,x.x,a,x.x,a*hh 1) Wind Angle, 0 to 360 degrees 2) Reference, R = Relative, T = True 3) Wind Speed 4) Wind Speed Units, K/M/N 5) Status, A = Data Valid 6) Checksum */ NMEAsentence = "$WIMWV," + String(WindBearing,2) + ",R," + String(LastWindSpeed,2) + ",N,A*" ; Serial.print(NMEAsentence); Serial.println(getCheckSum(NMEAsentence),HEX);; a = LastWindSpeed; } } void get_WindBearing() { cosinus = analogRead(A1) - ref; sinus = analogRead(A2) - ref; if (cosinus>0){ WindBearing = 90-atan(sinus/cosinus)*(180/PI); }else if (cosinus<0){ WindBearing = 270-atan(sinus/cosinus)*(180/PI); }else if (cosinus==0 & sinus<0){ WindBearing = 180; }else{ WindBearing = 0; } //WindBearing = 360 - WindBearing; indien omgedraaid moet worden } void calc_wind_speed() { double pulse_time = millis() - previousPulseMillis ; previousPulseMillis = millis(); LastWindSpeed = speedCompensation/pulse_time; } int getCheckSum(String s) { int i, XOR, c; for (XOR = 0, i = 0; i < s.length(); i++) { c = (unsigned char)s.charAt(i); if (c == '*') break; if ((c!='$') && (c!='!')) XOR ^= c; } return XOR; } void getSettings() { ref = analogRead(A3); speedCompensation = analogRead(A4); }