Ok.
I am new here. I got chewed out a few days ago for posting too much code, so here is the entire script.
#include "Arduino_H7_Video.h"
#include "Arduino_GigaDisplayTouch.h"
#include "lvgl.h"
#include <ui.h>
#include <Wire.h>
#include <Adafruit_BMP280.h>
#include <AHT20.h>
AHT20 aht20;
Adafruit_BMP280 bmp; // use I2C interface
Adafruit_Sensor *bmp_temp = bmp.getTemperatureSensor();
Adafruit_Sensor *bmp_pressure = bmp.getPressureSensor();
Arduino_H7_Video Display( 800, 480, GigaDisplayShield ); //( 800, 480, GigaDisplayShield );
Arduino_GigaDisplayTouch TouchDetector;
// These constants won't change. They're used to give names to the pins used:
//const int analogOutPin = A3; // Analog output pin that the DMX data is written to
int DMX_Value = 0; // init
int direction= 0; //value read from the wind vane
int windspeed= 0; //value read from the anamometer
int ui_Button_DMX_Transmit;
int temperature = 0;
int humidity = 0;
float pressure = 0;
void setup() {
Display.begin();
TouchDetector.begin();
Serial.begin(9600);
Wire.begin();
if (aht20.begin() == false)
{
Serial.println("AHT20 not detected. Please check wiring. Freezing.");
while(true);
}
while ( !Serial ) delay(100); // wait for native usb
unsigned status;
status = bmp.begin();
if (!status) {
Serial.println(F("Could not find a valid BMP280 sensor, check wiring or "
"try a different address!"));
while (1) delay(10);
}
/* Default settings from datasheet. */
bmp.setSampling(Adafruit_BMP280::MODE_NORMAL, /* Operating Mode. */
Adafruit_BMP280::SAMPLING_X2, /* Temp. oversampling */
Adafruit_BMP280::SAMPLING_X16, /* Pressure oversampling */
Adafruit_BMP280::FILTER_X16, /* Filtering. */
Adafruit_BMP280::STANDBY_MS_500); /* Standby time. */
bmp_temp->printSensorDetails();
pinMode(A3, OUTPUT); // prepare Giga to output DMX (windspeed & direction)
ui_init();
}
// this section is for DMX Transmit function
// ui_LBL_Transmit_DMX variable used in this section
// ui_LBL_Transmit_DMX =(the raw data read)
void loop()
{
lv_timer_handler();
sensors_event_t temp_event, pressure_event;
bmp_temp->getEvent(&temp_event);
bmp_pressure->getEvent(&pressure_event);
float humidity = aht20.getHumidity();
if (digitalRead(A3) == LOW) {analogWrite(A3, 0);} // look at code here for DMX Enable
int DMX_Value = map(direction, 0, 3610, 0, 255); // remap the analog out value for DMX:
analogWrite(A3, DMX_Value); // send DMX data on pin A3
if (ui_Button_DMX_Transmit > 0) { // send DMX data on pin A3 or not
analogWrite(A3, DMX_Value);
} else {analogWrite(A3, 0);
}
// print the results to the Serial Monitor:
Serial.print("DMX = ");
Serial.print(DMX_Value);
Serial.print("\t Direction = ");
Serial.println(direction/10);
Serial.print("\t windspeed = ");
Serial.println(windspeed);
Serial.println(ui_Button_DMX_Transmit);
//if (ui_Button_DMX_Transmit1=true);
// wait 2 milliseconds before the next loop for the analog-to-digital
// converter to settle after the last reading:
// this section is for weathervane read and display
// variable used in this section
// Weather_vane =(the raw data read from the sensor)
// float voltage = (calculated wind direction corrected for scale)
// direction = (the wind direction displayed on the ui)
int Weather_vane = analogRead(A0);
float voltage = Weather_vane*5/600.0;
//correct low end jitter
if(voltage < .02){
voltage = 0;
}
direction = map(Weather_vane, 0, 102.9, 0, 360);
lv_img_set_angle(ui_Weather_Vane_Pointer1, direction); // wind direction image screen1
lv_img_set_angle(ui_Weather_Vane_Pointer2, direction); // wind direction image screen2
lv_label_set_text_fmt(ui_Weather_Vane_Data, "%d", (direction/10)); // wind direction text screen1
lv_label_set_text_fmt(ui_Weather_Vane_Data1, "%d", (direction/10)); // wind direction text screen2
// windvane section end
// this section is for anemometer read and display
// variable used in this section
// anemometer =(the raw data read from the sensor)
// float voltage = (calculated windspeed corrected for scale)
// windspeed = (the speed displayed on the ui)
{
int anemometer = analogRead(A1); // write data to pin 1
float voltage1 = anemometer*5/102.0; // scale data
//correct low end jitter
if(voltage1 < .02){
voltage1 = 0;
}
windspeed = map(anemometer, 0, 636, 0, 50); // remap data
// print out the value you read:
// the next lines place values into the components both in both panels and both screens
lv_bar_set_value(ui_Bar1, windspeed, LV_ANIM_ON); //windspeed bar screen 1
lv_bar_set_value(ui_Bar2, windspeed, LV_ANIM_ON); //windspeed bar screen 2
lv_label_set_text_fmt(ui_Anenometer_Data, "%d", windspeed); //windspeed screen 1
lv_label_set_text_fmt(ui_Anenometer_Data1, "%d", windspeed); //windspeed screen 2
}
// thissection for temperature, pressure, humidity
{
temperature=((temp_event.temperature *1.8)+32);
pressure = ((pressure_event.pressure / 33.8639) +.568);
lv_label_set_text_fmt(ui_Temperature_Data, "%d", temperature);
lv_label_set_text_fmt(ui_Temperature_Data1, "%d", temperature);
lv_label_set_text_fmt(ui_Pressure_Data, "%d", pressure);
lv_label_set_text_fmt(ui_Pressure_Data1, "%d", pressure);
}
delay(1000);
}
// anemometer section end