/* SDL_Weather_80422_Library.ino - Example for using SDL_Weather_80422 Library For Weather Sensor Assembly 80422. Imported by Argent Data Systems Created by SwitchDoc Labs July 27, 2014. Released into the public domain. */ #include #include #include "SDL_Weather_80422.h" #define pinLED 13 // LED connected to digital pin 13 #define pinAnem 18 // Anenometer connected to pin 18 - Int 5 #define pinRain 2 // Rain Bucket connecto to pin 19 - Int 4 #define intAnem 5 #define intRain 0 // for mega, have to use Port B - only Port B works. /* Arduino Pins PORT ------------ ---- Digital 0-7 D Digital 8-13 B Analog 0-5 C */ // initialize SDL_Weather_80422 library SDL_Weather_80422 weatherStation(pinAnem, pinRain, intAnem, intRain, A0, SDL_MODE_INTERNAL_AD); uint8_t i; float currentWindSpeed; float currentWindGust; float totalRain; void setup() { Serial.begin(57600); Serial.println("-----------"); Serial.println("WeatherArduino SDL_Weater_80422 Class Test"); Serial.println("Version 1.1"); Serial.println("-----------"); weatherStation.setWindMode(SDL_MODE_SAMPLE, 5.0); totalRain = 0.0; } void loop() { Serial.println("----------------"); currentWindSpeed = weatherStation.current_wind_speed()/1.6; currentWindGust = weatherStation.get_wind_gust()/1.6; totalRain = totalRain + weatherStation.get_current_rain_total()/25.4; Serial.print("rain_total="); Serial.print(totalRain); Serial.print(""" wind_speed="); Serial.print(currentWindSpeed); Serial.print("MPH wind_gust="); Serial.print(currentWindGust); Serial.print("MPH wind_direction="); Serial.println(weatherStation.current_wind_direction()); delay(1000); } weatherStation.setWindMode(SDL_MODE_DELAY, 5.0); pinMode(pinAnem, INPUT); // pinAnem is input to which a switch is connected digitalWrite(pinAnem, HIGH); // Configure internal pull-up resistor pinMode(pinRain, INPUT); // pinRain is input to which a switch is connected digitalWrite(pinRain, HIGH); // Configure internal pull-up resistor attachInterrupt(_intAnem, serviceInterruptAnem, RISING); attachInterrupt(_intRain, serviceInterruptRain, RISING); unsigned long lastWindTime; void serviceInterruptAnem() { unsigned long currentTime= (unsigned long)(micros()-lastWindTime); lastWindTime=micros(); if(currentTime>1000) // debounce { SDL_Weather_80422::_currentWindCount++; if(currentTime void ExecuteLocalSIMPLE_LINE_GRAPH_LIVE_UITYPE(char returnJSON[], char *buffer, currentObjectStructure *parsedObject) { // SLGL-1 returns the current wind speed graph if (strcmp(parsedObject->ObjectServerID, "SLGL-1") == 0) { if (strcmp(parsedObject->Validate, "YES") == 0) { // send validated response returnJSONValidateResponse(returnJSON, returnJSON, parsedObject); strcpy(returnJSON, buffer); return; } char responseData[200]; sprintf(responseData, "%s", windSpeedBuffer); returnJSONResponse(returnJSON, returnJSON, parsedObject, responseData ); strcpy(returnJSON, buffer); return; } } sprintf(responseData, "%s", windSpeedBuffer); char windSpeedBuffer[150]; // wind speed graph SDL_RasPiGraphLibrary windSpeedGraph(10,SDL_MODE_LABELS); windSpeedGraph.add_value(currentWindSpeed); windSpeedGraph.getRasPiString(windSpeedBuffer, windSpeedBuffer);