Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Wire.h>
- #include <Adafruit_Sensor.h>
- #include <Adafruit_GFX.h> // Core graphics library
- #include <Adafruit_ST7735.h> // Hardware-specific library
- #include <Adafruit_BME280.h>
- #include <SPI.h>
- #include <math.h>
- #include "Adafruit_TMP007.h"
- #define TFT_CS 10
- #define TFT_RST 0 // Tied to Arduino Reset
- #define TFT_DC 8 // A0 China Board
- #define TFT_SCLK 13 // set these to be whatever pins you like!
- #define TFT_MOSI 11 // SDA CHINA
- #define SEALEVELPRESSURE_HPA (1013.25)
- int UVOUT = A0; //Output from ML8511
- int REF_3V3 = A3; //3.3V power for Reference calculation
- float dew;
- float pressure;
- double VP;
- float temp;
- float hum;
- int page = 1;
- int selection = 0;
- unsigned long color;
- int pagechange = 0;
- int keyHit = 0;
- int changescreen = 0;
- int sleepstatus = 1;
- int brightness = 200;
- volatile int readstatus = 0;
- volatile int ButtonSelection = 0;
- Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
- Adafruit_BME280 bme;
- Adafruit_TMP007 tmp007;
- void setup(void) {
- analogWrite(5, brightness); // Screen Backlight set
- Wire.begin();
- buttonrequest();
- bme.begin();
- tmp007.begin(TMP007_CFG_16SAMPLE);
- pinMode(UVOUT, INPUT);
- pinMode(REF_3V3, INPUT);
- pinMode(2, INPUT_PULLUP);
- pinMode(3, INPUT_PULLUP);
- pinMode(9, OUTPUT);
- analogWrite(5, brightness); // Screen Backlight set
- digitalWrite(7, LOW);
- Serial.begin(9600);
- attachInterrupt(digitalPinToInterrupt(2), buttonread, FALLING);
- tft.initR(INITR_BLACKTAB); // initialize a ST7735S chip
- for (int i = 0x20; i <=0x24; i++) // Loop to set Button Negative Thresholds
- {
- Wire.beginTransmission(0x1B);
- Wire.write(i);
- Wire.write(15);
- Wire.endTransmission();
- delay(100);
- }
- Serial.println("Setup Complete");
- }
- void loop() {
- if (page == 1) homescreen();
- if (page == 2) temperature();
- if (page == 3) wind();
- if (page == 4) light();
- if (page == 5) altitude();
- if (page == 6) humidity();
- if (page == 7) settings();
- }
- void settings(){
- int select = 0;
- int brightnessbar;
- detachInterrupt(digitalPinToInterrupt(2));
- tft.fillScreen(ST7735_BLACK);
- for (int box = 0; box <=3; box++){ //predraw selection boxes
- tft.drawRect(0, 20+(box*35), 128, 34, ST7735_YELLOW);
- }
- tft.fillRect(5, 34, 118, 15, ST7735_YELLOW); // predraw Brightness
- brightnessupdate();
- tft.setCursor(35, 5);tft.print("SETTINGS");
- tft.setCursor(30, 24);tft.print("BRIGHTNESS");
- tft.setCursor(25, 58);tft.print("AUTO-OFF TIME");
- tft.setCursor(45, 93);tft.print("UNITS");
- tft.setCursor(11, 128);tft.print("SEA LEVEL PRESSURE");
- tft.setTextSize(2);
- while (changescreen == 0) {
- tft.drawRect(0, 20+(select*35), 128, 34, ST7735_WHITE);
- tft.drawRect(1, 21+(select*35), 126, 32, ST7735_WHITE);
- while (readstatus == 0){
- buttonrequest();
- }
- if (ButtonSelection == 1 || ButtonSelection == 8) {
- tft.drawRect(0, 20+(select*35), 128, 34, ST7735_YELLOW);
- tft.drawRect(1, 21+(select*35), 126, 32, ST7735_BLACK);
- if (ButtonSelection == 1) select = select - 1;
- if (ButtonSelection == 8) select = select + 1;
- if (select < 0) select = 3;
- if (select > 3) select = 0;
- while (readstatus == 1) buttonrequest();
- }
- if (ButtonSelection == 2 || ButtonSelection == 16) {
- if (ButtonSelection == 2 && brightness > 25) brightness = brightness - 2;
- if (ButtonSelection == 16 && brightness < 250) brightness = brightness + 2;
- analogWrite(5, brightness); // Screen Backlight set
- brightnessupdate();
- }
- if (ButtonSelection == 4){
- changescreen = 1;
- }
- readstatus = 0;
- // if (ButtonSelection == 16) right = 1;
- // if (ButtonSelection == 2) left = 1;
- // if (ButtonSelection == 4) select = 1;
- }
- attachInterrupt(digitalPinToInterrupt(2), buttonread, FALLING);
- Navigate();
- }
- void homescreen(){
- tft.fillScreen(ST7735_BLACK);
- tft.setTextSize(1);
- tft.setTextColor(0xFE60, ST7735_BLACK);
- tft.setCursor(3, 0);tft.print("Aer One");
- tft.drawRect(88, 1, 15, 6, 0xFE60);
- tft.fillRect(90, 3, 8, 2, 0xFE60);
- tft.setTextSize(2);
- tft.setTextColor(ST7735_BLACK);
- drawButton(255,0,54,0,152,119,4,11);
- tft.setCursor(45, 15);tft.print("TEMP");
- drawButton(255,91,0,0,101,0,4,36);
- tft.setCursor(45, 40);tft.print("WIND");
- drawButton(255,206,0,0,41,175,4,61);
- tft.setCursor(18, 65);tft.print("UV LIGHT");
- drawButton(59,170,72,0,63,0,4,86);
- tft.setCursor(18, 90);tft.print("PRESSURE");
- drawButton(0,100,255,0,100,0,4,111);
- tft.setCursor(18, 115);tft.print("HUMIDITY");
- drawButton(154,49,255,65,117,0,4,136);
- tft.setCursor(18, 140);tft.print("SETTINGS");
- tft.setTextSize(1);tft.setTextColor(ST7735_YELLOW,ST7735_BLACK);
- while (changescreen == 0) {
- tft.drawRect(3, (selection * 25)+10, 122, 24, ST7735_WHITE);
- tft.drawRect(4, (selection * 25)+11, 120, 22, ST7735_WHITE);
- while (ButtonSelection == 0) {
- int battery = mapfloat(averageAnalogRead(7), 650, 850, 1, 100); // Air Indicator Check and Update
- tft.setCursor(107, 0);tft.print(battery); tft.print("%"); //battery indicator
- delay(1);
- }
- tft.drawRect(3, (selection * 25)+10, 122, 24, ST7735_BLACK);
- tft.drawRect(4, (selection * 25)+11, 120, 22, ST7735_BLACK);
- if (ButtonSelection == 1){
- selection = selection - 1;
- if (selection < 0) selection = 5;
- ButtonSelection = 0;
- }
- if (ButtonSelection == 8){
- selection = selection + 1;
- if (selection > 5) selection = 0;
- ButtonSelection = 0;
- }
- if (ButtonSelection == 4){
- changescreen = 1;
- ButtonSelection = 0;
- page = selection +2;
- }
- }
- Navigate();
- }
- void temperature(){
- tft.fillScreen(ST7735_BLACK);
- float g = 0; float b = 255; float r = 0;
- int aircheck;
- int ircheck = 0;
- unsigned long gradientcolor;
- // Air Temperature Gradient
- for (int t = 0 ; t <= 128 ; t++) {
- r = (r + 1.6);
- b = (b - 1.6);
- tft.drawFastVLine(t,15, 15, ((long (r) / 8) << 11) | ((long (g) / 4) << 5) | (long (b) / 8));
- }
- //Infrared Temperature Gradient
- r = 0; g = 0; b = 255;
- for (int t = 0 ; t <= 64 ; t++) {
- r = (r + 3.8);
- b = (b - 3.8);
- tft.drawFastVLine(t,82, 15, ((long (r) / 8) << 11) | ((long (g) / 4) << 5) | (long (b) / 8));
- }
- for (int t = 65 ; t <= 128 ; t++) {
- g = (g + 3.8);
- tft.drawFastVLine(t,82, 15, ((long (r) / 8) << 11) | ((long (g) / 4) << 5) | (long (b) / 8));
- }
- tft.drawRect(0, 0, 128, 65, ST7735_YELLOW);
- tft.drawRect(0, 66, 128, 65, ST7735_WHITE);
- tft.setTextColor(ST7735_WHITE);
- tft.setCursor(3, 72); tft.print("Infrared Temperature");
- StandardText();
- tft.setCursor(20, 5); tft.print("Air Temperature");
- tft.setCursor(5, 140); tft.print("Heat Index:");
- tft.setCursor(5, 150); tft.print("Dew Point");
- tft.setCursor(120, 140); tft.print("F");
- tft.setCursor(120, 150); tft.print("F");
- digitalWrite(9, HIGH); // Laser On
- while (changescreen == 0) {
- pressure = (bme.readPressure()/ 100.0F);
- float irc = tmp007.readObjTempC();
- Serial.println("irc");
- Serial.println(irc);
- float irf = (CtoF(irc));
- Serial.println("irf");
- Serial.println(irf);
- float tempc = bme.readTemperature();
- Serial.println("tempc");
- Serial.println(tempc);
- float tempf = (CtoF(tempc));
- Serial.println("tempf");
- Serial.println(tempf);
- float hum = (bme.readHumidity());
- dewPoint(bme.readTemperature(), hum);
- tft.setTextSize(2);
- tft.setCursor(54, 45); tft.print((int)tempf); //Temperature
- tft.setCursor(54, 113); tft.print((int)irf);tft.print(" "); //IR Temperature
- int airtriangle = mapfloat(tempf, 32, 100, 5, 123); // Air Indicator Check and Update
- int irtriangle = mapfloat(irf, 32, 200, 5, 123); // ir Indicator Check and Update
- if (irtriangle != ircheck) {
- tft.fillRect(1, 100, 126, 10, ST7735_BLACK); // Clear ir Indicator
- tft.fillTriangle(irtriangle, 100, irtriangle-5, 109, irtriangle+5, 109, ST7735_YELLOW);
- ircheck = irtriangle;
- }
- if (airtriangle != aircheck) {
- tft.fillRect(1, 31, 126, 10, ST7735_BLACK); // Clear Air Indicator
- tft.fillTriangle(airtriangle, 31, airtriangle-5, 40, airtriangle+5, 40, ST7735_YELLOW);
- aircheck = airtriangle;
- }
- StandardText();
- tft.setCursor(84, 140); tft.print((0.5 * (tempf + 61.0 + ((tempf-68.0)*1.2) + (hum*0.094)))); //Heat Index
- tft.setCursor(84, 150); tft.print(CtoF(dew));
- }
- digitalWrite(9, LOW); // laser Off
- Navigate();
- }
- void humidity(){
- int xval[] = {95, 114, 86, 104, 76, 110, 91, 98, 94, 100, 101, 90, 83, 110, 116, 114, 81, 74, 90};
- int yval[] = {48, 53, 63, 33, 46, 62, 27, 60, 34, 68, 50, 43, 32, 26, 38, 44, 53, 63, 68};
- unsigned long dots;
- float abshum;
- tft.fillScreen(ST7735_BLACK);
- tft.fillCircle(31, 67, 17, 0x4EDC); //relative humidity droplet
- tft.fillTriangle(15, 60, 47, 60, 31, 25, 0x4EDC); //relative humidity droplet
- tft.fillTriangle(31, 32, 31, 40, 38, 50, ST7735_WHITE); //Droplet upper 3D Mark
- // tft.fillTriangle(30, 82, 19, 75, 22, 73, ST7735_WHITE); //Droplet lower 3D Mark
- tft.drawRect(0, 0, 64, 91, 0xBA80); // UI top left box
- tft.drawRect(65, 0, 63, 91, 0xBA80); // UI top right box
- tft.drawRect(0, 138, 128, 22, 0xBA80); // UI bottom PPM
- tft.drawRect(0, 115, 128, 22, 0xBA80); // UI bottom saturation
- tft.drawRect(0, 92, 128, 22, 0xBA80); // UI bottom vapor pressure
- for (int i = 0; i <= 33; i++) { // AH bottom plane
- tft.drawLine(86 + i, 57, 71 + i, 72, 0xFD6C);
- }
- for (int i = 0; i <= 34; i++) { // AHleft-side plane
- tft.drawLine(86, 57-i, 71, 72-i, 0xFD6C);
- }
- tft.fillRect(86, 23, 35, 35, 0xFD6C);
- tft.drawRect(86, 23, 35, 35, 0xBA80); // AH top right box
- tft.drawLine(86, 57, 86, 23, 0xE71C);// AH lighter line verticle
- tft.drawLine(86, 57, 119, 57, 0xE71C);// AH lighter line horizontal
- tft.drawRect(71, 38, 35, 35, 0xBA80); //AH bottom left box
- tft.drawLine(86, 23, 71, 38, 0xBA80); // AH top left
- tft.drawLine(120, 23, 105, 38, 0xBA80); // AH top right
- tft.drawLine(86, 57, 72, 71, 0xE71C);// AH bottom left angle line
- tft.drawLine(120, 57,105, 72, 0xBA80);// AH bottom right
- StandardText();
- tft.setCursor(7, 3); tft.print("Relative");
- tft.setCursor(7, 13); tft.print("Humidity");
- tft.setCursor(73, 3); tft.print("Absolute ");
- tft.setCursor(73, 13); tft.print("Humidity");
- tft.setCursor(4, 94); tft.print("Water Vapor Pressure");
- tft.setCursor(7, 117); tft.print("Saturation Pressure");
- tft.setCursor(4, 140); tft.print("Water Concentration");
- tft.setCursor(101, 78); tft.print("g/m3");
- tft.setCursor(80, 104); tft.print("hPa"); // vapor pressure hPa
- tft.setCursor(80, 127); tft.print("hPa"); // saturation pressure hPa
- tft.setCursor(80, 150); tft.print("PPM"); // Water PPM
- tft.setTextSize(2);
- tft.setTextColor(0x4EDC, ST7735_BLACK);
- tft.setCursor(50, 60); tft.print("%");
- while (changescreen == 0) {
- hum = bme.readHumidity();
- temp = bme.readTemperature();
- pressure = (bme.readPressure()/ 100.0F);
- dewPoint(temp, hum);
- abshum = (2.16679 * ((VP*1000)/(temp+273.15)));
- tft.setTextColor(ST7735_BLACK,0x4EDC);
- tft.setTextSize(2);
- tft.setCursor(21, 60); tft.print(int(bme.readHumidity()));
- tft.setTextSize(1);
- tft.setTextColor(0x4EDC, ST7735_BLACK);
- if (abshum > 9.99) {
- tft.setCursor(69, 78);tft.print(abshum); //Absolute Humidity
- }
- else {
- tft.setCursor(69, 78);tft.print(" "); //Absolute Humidity
- tft.setCursor(74, 78);tft.print(abshum); //Absolute Humidity
- }
- for (int i = 0; i < 19; i++) {
- if ((abshum - 4) * 5 > i) dots = 0x631F; //blue
- if ((abshum - 4) * 5 < i) dots = 0xFD6C; // light orange
- tft.fillCircle(xval[i], yval[i], 2, dots); // dots
- }
- tft.setCursor(40, 127); tft.print((VP / (hum/100)*10)); // saturation pressure
- tft.setCursor(40, 150); tft.print(int(pow(10, 6)*((VP*10)/(pressure-(VP*10)))));
- if ((VP*10)> 9.99) {
- tft.setCursor(40, 104);tft.print(VP*10); //Water Vapor Pressure
- }
- else {
- tft.setCursor(40, 104);tft.print(" "); //Water Vapor Pressure
- tft.setCursor(45, 104);tft.print(VP*10); //Water Vapor Pressure
- }
- }
- Navigate();
- }
- void altitude(){
- tft.fillScreen(ST7735_BLACK);
- tft.fillTriangle(34, 90, 94, 90, 64, 20, 0x79E0); //Large Mountain
- tft.fillTriangle(8, 90, 64, 90, 44, 30, 0x79E0); //Left Mountain
- tft.fillTriangle(54, 90, 120, 90, 90, 40, 0x79E0); //Right Mountain
- StandardText();
- tft.setCursor(28, 102);
- tft.print("Air Pressure:");
- tft.setCursor(40, 5);
- tft.print("Altitude");
- tft.setCursor(100, 125);
- tft.print(" hPa");
- tft.setTextColor(ST7735_YELLOW,0x79E0);
- tft.setCursor(100, 73);
- tft.print("m");
- tft.setTextSize(2);
- while (changescreen == 0) {
- pressure = (bme.readPressure()/ 100.0F);
- tft.setTextColor(ST7735_YELLOW,0x79E0); tft.setCursor(34, 73); tft.print(int(bme.readAltitude(SEALEVELPRESSURE_HPA)));
- tft.setTextColor(ST7735_YELLOW,ST7735_BLACK); tft.setCursor(26, 120); tft.print(pressure);
- }
- Navigate();
- }
- void wind(){
- tft.fillScreen(ST7735_BLACK);
- digitalWrite(7, HIGH);
- StandardText();
- tft.setCursor(3, 10);
- tft.print("Raw Wind Reading");
- tft.setCursor(3, 50);
- tft.print("Compensation Adjust");
- tft.setCursor(3, 90);
- tft.print("Wind Chill");
- tft.setTextSize(2);
- while (changescreen == 0) {
- float T = CtoF(bme.readTemperature());
- float V = 10;
- float raw = analogRead(A1);
- float out = analogRead(A6);
- float Windchill = 35.74 + 0.6215*T - 35.75*pow(V,0.16) + 0.4275*T*pow(V,0.16);
- tft.setCursor(10, 25);
- tft.print(raw);
- tft.setCursor(10, 65);
- tft.print(out);
- tft.setCursor(10, 105);
- tft.print(Windchill);
- }
- digitalWrite(7, LOW);
- Navigate();
- }
- void light(){
- float r = 255;
- float b = 0;
- float g = 255;
- int uvcheck = 0;
- int uvTriangle = 0;
- int flare = 1;
- int prevflare = 1;
- unsigned long color;
- tft.fillScreen(ST7735_BLACK);
- StandardText();
- tft.setCursor(35, 5); tft.print("UV Intensity");
- tft.fillCircle(64, 75, 22, ST7735_YELLOW); //light
- tft.setTextColor(ST7735_BLACK,ST7735_YELLOW);
- for (int t = 0 ; t <= 128 ; t++) {
- g = (g - 1.6);
- tft.drawFastVLine(t,145, 15, ((long (r) / 8) << 11) | ((long (g) / 4) << 5) | (long (b) / 8));
- }
- tft.setTextColor(ST7735_BLACK);
- tft.setCursor(2, 149); tft.print("LOW");
- tft.setCursor(98, 151); tft.print("HIGH");
- tft.setTextSize(2);
- tft.setTextColor(ST7735_BLACK, ST7735_YELLOW);
- while (changescreen == 0) {
- int uvLevel = averageAnalogRead(UVOUT);
- int refLevel = averageAnalogRead(REF_3V3);
- //Use the 3.3V power pin as a reference to get a very accurate output value from sensor
- float outputVoltage = 3.3 / refLevel * uvLevel;
- float uvIntensity = mapfloat(outputVoltage, 0.99, 2.8, 0.0, 15.0); //Convert the voltage to a UV intensity level
- if (uvIntensity >= 0.2){
- tft.setCursor(46, 69); tft.print(uvIntensity,1);
- uvTriangle = mapfloat(uvIntensity, 0, 15, 5, 123); // UV Indicator Check and Update
- flare = mapfloat(uvIntensity, 0, 6, 10, 25); // UV Indicator Check and Update
- }
- else {
- tft.setCursor(46,69); tft.print("0.0");
- uvTriangle = 5;
- flare = 10;
- }
- // for (int y = 1 ; y <= 25 ; y++) {
- while (flare != prevflare){
- if (prevflare > flare) color = ST7735_BLACK;
- if (prevflare < flare) color = ST7735_YELLOW;
- tft.drawLine(59, 48,64, 49-prevflare, color);// Top Flare left line
- tft.drawLine(69, 48,64, 49-prevflare, color);// Top Flare right line
- tft.drawLine(59, 103,64, 102+prevflare, color);// Bottom Flare Left Line
- tft.drawLine(69, 103,64, 102+prevflare, color);// Bottom Flare Right Line
- tft.drawLine(91, 70,90+prevflare, 75, color);// Right Flare
- tft.drawLine(91, 80,90+prevflare, 75, color);// Right Flare
- tft.drawLine(37, 70,38-prevflare, 75, color);// Left Flare
- tft.drawLine(37, 80,38-prevflare, 75, color);// Left Flare
- tft.drawLine(78, 97,82+(prevflare/1.4), 94+(prevflare/1.4), color);// Bottom-Right Flare Left Line
- tft.drawLine(86, 91,82+(prevflare/1.4), 94+(prevflare/1.4), color);// Bottom-Right Flare Right Line
- tft.drawLine(42, 90,46-(prevflare/1.4), 94+(prevflare/1.4), color);// Bottom-Left Flare Left Line
- tft.drawLine(50, 97,46-(prevflare/1.4), 94+(prevflare/1.4), color);// Bottom-LEFT Flare Right Line
- tft.drawLine(42, 60,46-(prevflare/1.4), 57-(prevflare/1.4), color);// Top-Left Flare Left Line
- tft.drawLine(50, 54,46-(prevflare/1.4), 57-(prevflare/1.4), color);// Top-LEFT Flare Right Line
- tft.drawLine(78, 54,82+(prevflare/1.4), 57-(prevflare/1.4), color);// Top-Right Flare Left Line
- tft.drawLine(86, 60,82+(prevflare/1.4), 57-(prevflare/1.4), color);// Top-Right Flare Right Line
- if (prevflare > flare) {
- prevflare = prevflare - 1;
- }
- if (prevflare < flare) {
- prevflare = prevflare + 1;
- }
- }
- if (uvTriangle != uvcheck) {
- tft.fillRect(0, 135, 126, 10, ST7735_BLACK); // UV Indicator
- tft.fillTriangle(uvcheck, 144, uvcheck - 5, 135, uvcheck + 5, 135, ST7735_BLACK);
- tft.fillTriangle(uvTriangle, 144, uvTriangle - 5, 135, uvTriangle + 5, 135, ST7735_YELLOW);
- uvcheck = uvTriangle;
- }
- }
- Navigate();
- }
- void buttonrequest(){
- Wire.beginTransmission(0x1B); // transmit to device
- Wire.write(0x02); // want to read detection status // set pointer
- Wire.endTransmission(); // stop transmitting
- Wire.requestFrom(0x1B, 1); // request 1 byte from slave device
- readstatus =Wire.read();
- Wire.beginTransmission(0x1B); // transmit to device
- Wire.write(0x03); // want to read key status // set pointer
- Wire.endTransmission(); // stop transmitting
- Wire.requestFrom(0x1B, 1); // request 1 byte from slave device
- ButtonSelection =Wire.read();
- delay(5);
- }
- void buttonread(){
- sei();
- buttonrequest();
- // to clear change int we must read both status bytes 02 and 03
- if (sleepstatus == 0) {
- CLKPR = 0x80;
- CLKPR = 0x00;
- analogWrite(5, brightness); // Screen Backlight
- ButtonSelection = 0;
- sleepstatus = 1;
- }
- if (ButtonSelection == 16 || ButtonSelection == 2 || ButtonSelection == 4) {
- changescreen = 1;
- }
- if (ButtonSelection == 4) {
- unsigned long selectpressed, check;
- selectpressed = millis();
- while (readstatus != 0){
- buttonrequest();
- check = millis();
- if ((check - selectpressed) >= 3000){
- analogWrite(5, 0); // Screen Backlight
- delay(2000);
- CLKPR = 0x80;
- CLKPR = 0x04;
- ButtonSelection = 0;
- sleepstatus = 0;
- changescreen = 0;
- }
- else {
- ButtonSelection = 4;
- }
- }
- }
- Serial.println(ButtonSelection);
- Serial.println(readstatus);
- }
- double dewPoint(double celsius, double humidity)
- {
- double RATIO = 373.15 / (273.15 + celsius);
- double RHS = -7.90298 * (RATIO - 1);
- RHS += 5.02808 * log10(RATIO);
- RHS += -1.3816e-7 * (pow(10, (11.344 * (1 - 1/RATIO ))) - 1) ;
- RHS += 8.1328e-3 * (pow(10, (-3.49149 * (RATIO - 1))) - 1) ;
- RHS += log10(pressure);
- // factor -3 is to adjust units - Vapor Pressure SVP * humidity
- VP = pow(10, RHS - 3) * humidity;
- // (2) DEWPOINT = F(Vapor Pressure)
- double T = log(VP/0.61078); // temp var
- dew = (241.88 * T) / (17.558 - T);
- }
- float CtoF(float celcius)
- {
- return (celcius * 18 + 5)/10 + 32;
- }
- //Takes an average of readings on a given pin
- //Returns the average
- int averageAnalogRead(int pinToRead)
- {
- byte numberOfReadings = 50;
- unsigned int runningValue = 0;
- for(int x = 0 ; x < numberOfReadings ; x++)
- runningValue += analogRead(pinToRead);
- runningValue /= numberOfReadings;
- return(runningValue);
- }
- //The Arduino Map function but for floats
- //From: http://forum.arduino.cc/index.php?topic=3922.0
- float mapfloat(float x, float in_min, float in_max, float out_min, float out_max)
- {
- return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
- }
- void StandardText() {
- tft.setTextColor(ST7735_YELLOW,ST7735_BLACK);
- tft.setTextSize(1);
- }
- void Navigate(){
- if (ButtonSelection == 16){
- page = (page + 1);
- if (page > 6) page = 1;
- if (page < 1) page = 6;
- ButtonSelection = 0;
- }
- if (ButtonSelection == 2){
- page = (page - 1);
- if (page > 6) page = 1;
- if (page < 1) page = 6;
- ButtonSelection = 0;
- }
- if (ButtonSelection == 4){
- selection = page - 2;
- page = 1;
- ButtonSelection = 0;
- }
- changescreen = 0;
- }
- void CalculateColor(long r, long g, long b){
- color = (r / 8) << 11 | (g / 4) << 5 | (b / 8);
- }
- void drawButton(long r, long g, long b, long rchange, int gchange, int bchange, int x, int y) {
- for (int t=1; t<=10; t++){
- CalculateColor(((rchange/10)*t)+r, ((gchange/10)*t)+g, ((bchange/10)*t)+b);
- tft.drawRect(x+t, y+t, 120-(t*2), 22-(t*2), color);
- }
- }
- void brightnessupdate(){
- int brightnessbar = int(mapfloat(brightness, 24, 250, 0, 118));
- tft.fillRect(5, 34, brightnessbar, 15, ST7735_YELLOW);
- tft.fillRect(brightnessbar + 6, 34, 118-brightnessbar, 7, ST7735_BLACK);
- tft.fillRect(brightnessbar + 6, 43, 118-brightnessbar, 7, ST7735_BLACK);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement