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
| #include <Wire.h> #include <SPI.h> #include <Adafruit_Sensor.h> #include <Adafruit_BMP280.h> #include <dht11.h> #include "SSD1306Wire.h" #define BLINKER_WIFI #include <Blinker.h>
#define temNumber "num-gpc" #define humNumber "num-ia5" #define windNumber "num-zb4" #define AirNumber "num-3zw"
char auth[] = "c2b25ef0c332"; char ssid[] = "皇室家族Family"; char pswd[] = "sunlisunrusunxu@";
BlinkerNumber Tem(temNumber); BlinkerNumber Hum(humNumber); BlinkerNumber Wind(windNumber); BlinkerNumber Air(AirNumber);
dht11 DHT11; #define DHT11PIN 2 const int I2C_ADDR = 0x3c; #define SDA_PIN 4 #define SCL_PIN 5
#define BMP_SCK 16 #define BMP_MISO 14 #define BMP_MOSI 13 #define BMP_CS 12
SSD1306Wire oled(I2C_ADDR, SDA_PIN, SCL_PIN); Adafruit_BMP280 bmp(BMP_CS, BMP_MOSI, BMP_MISO, BMP_SCK); String number[]={"0","1","2","3","4","5","6","7","8","9"}; static const uint8_t text[][32]={ 0x10,0x04,0x60,0x04,0x02,0x7E,0x8C,0x01,0x00,0x40,0x00,0x7E,0xFE,0x42,0x92,0x42,0x92,0x7E,0x92,0x42,0x92,0x7E,0x92,0x42,0xFE,0x42,0x00,0x7E,0x00,0x40,0x00,0x00, 0x00,0x40,0x00,0x30,0xFC,0x8F,0x24,0x80,0x24,0x84,0x24,0x4C,0xFC,0x55,0x25,0x25,0x26,0x25,0x24,0x25,0xFC,0x55,0x24,0x4C,0x24,0x80,0x24,0x80,0x04,0x80,0x00,0x00, 0x10,0x04,0x60,0x04,0x02,0x7E,0x8C,0x01,0x00,0x44,0xFE,0x48,0x92,0x50,0x92,0x7F,0x92,0x40,0x92,0x40,0x92,0x7F,0x92,0x50,0xFE,0x48,0x00,0x44,0x00,0x40,0x00,0x00, 0x00,0x40,0x00,0x30,0xFC,0x8F,0x24,0x80,0x24,0x84,0x24,0x4C,0xFC,0x55,0x25,0x25,0x26,0x25,0x24,0x25,0xFC,0x55,0x24,0x4C,0x24,0x80,0x24,0x80,0x04,0x80,0x00,0x00, 0x00,0x80,0x00,0x60,0xFE,0x1F,0x02,0x00,0x12,0x20,0x22,0x10,0xC2,0x0C,0x02,0x03,0xC2,0x0C,0x32,0x30,0x02,0x00,0xFE,0x0F,0x00,0x30,0x00,0x40,0x00,0xF8,0x00,0x00, 0x40,0x00,0x40,0x40,0x42,0x20,0xCC,0x1F,0x00,0x20,0x04,0x48,0xF4,0x44,0x94,0x42,0x94,0x41,0xFF,0x5F,0x94,0x41,0x94,0x42,0xF4,0x44,0x04,0x48,0x00,0x40,0x00,0x00, 0x20,0x00,0x10,0x00,0x4C,0x00,0x47,0x00,0x54,0x00,0x54,0x00,0x54,0x00,0x54,0x00,0x54,0x00,0x54,0x00,0x54,0x00,0xD4,0x0F,0x04,0x30,0x04,0x40,0x00,0xF0,0x00,0x00, 0x00,0x80,0x00,0x60,0xFE,0x1F,0x02,0x40,0x82,0x40,0x82,0x40,0x82,0x40,0x82,0x40,0xFA,0x7F,0x82,0x40,0x82,0x40,0x82,0x44,0x82,0x58,0x82,0x40,0x02,0x40,0x00,0x00, };
float wind=0.0; float wind_value=0.0;
void setup() { Serial.begin(9600);
Blinker.begin(auth, ssid, pswd);
oled.init(); oled.flipScreenVertically(); oled.setContrast(255); drawRect(); oled.clear(); oled.display();
}
void loop() { Blinker.run(); bmp.begin(); Serial.println("\n"); DHT11.read(DHT11PIN); delay(500);
int sensorValue = analogRead(A0); float wind = sensorValue * (5.0 / 1024.0); wind_value=100*wind-4.39; oled.setFont(ArialMT_Plain_16); oled.clear(); oled.drawFastImage(4 + 16*0, 0, 16, 16, text[0]); oled.drawFastImage(4 + 16*1, 0, 16, 16, text[1]); oled.drawFastImage(18 + 16*3, 0, 16, 16, text[2]); oled.drawFastImage(18 + 16*4, 0, 16, 16, text[3]); oled.drawFastImage(4 + 16*0, 19, 16, 16, text[4]); oled.drawFastImage(4 + 16*1, 19, 16, 16, text[5]); oled.drawFastImage(4 + 16*0, 19*2, 16, 16, text[6]); oled.drawFastImage(4 + 16*1, 19*2, 16, 16, text[7]); oled.drawString(4 + 16*2, 0, ":"+number[DHT11.temperature/10]+number[DHT11.temperature%10]); oled.drawString(18 + 16*5, 0, ":"+number[DHT11.humidity/10]+number[DHT11.humidity%10]); oled.drawString(4 + 16*2, 19, ":"+number[(int)wind_value/100]+number[(int)wind_value/10%10]+number[(int)wind_value%10]+"."+number[((int)(wind_value*100))/10%10]+number[((int)(wind_value*100))%10]+"km/h"); pressuCheck(); oled.display(); Tem.print(DHT11.temperature); Hum.print(DHT11.humidity); Wind.print(wind_value);
} void drawRect(void) { for (int16_t i=0; i<oled.getHeight()/2; i+=2) { oled.drawRect(i, i, oled.getWidth()-2*i, oled.getHeight()-2*i); oled.display(); delay(50); } } void pressuCheck() { float Pressure=0.0; int Pressure1,Pressure2,Pressure3,Pressure4,Pressure5,Pressure6,Pressure7,Pressure8; Pressure=bmp.readPressure();
Pressure1=(int)Pressure/100000; Pressure2=(int)Pressure/10000%10; Pressure3=(int)Pressure/1000%10; Pressure4=(int)Pressure/100%10; Pressure5=(int)Pressure/10%10; Pressure6=(int)Pressure%10; Pressure7=((int)(Pressure*100))/10%10; Pressure8=((int)(Pressure*100))%10; oled.drawString(4 + 16*2, 19*2, ":"+number[Pressure1]+number[Pressure2]+number[Pressure3]+number[Pressure4]+number[Pressure5]+number[Pressure6]+"."+number[Pressure7]+number[Pressure8]+"P"); Air.print(Pressure); }
|