本帖最后由 ☆琥珀川☆ 于 2013-7-19 10:17 编辑
炎炎夏日,做个温度计看看究竟有多热,用的Arduino Mini Pro 5V/8M, SHT71温度湿度传感器,OLED显示屏(SSD1306芯片,淘宝上一堆),Micro-USB电源口,随便找个手机充电器插上就可以了。
上图片先。
背面焊的有点乱,大家轻拍。。。
开机图片。
代码来了,用到了几个库,附件里下载,省得大家到处去找。
- #include <Wire.h>
- #include <Adafruit_GFX.h>
- #include <Adafruit_SSD1306.h>
- #include <SHT1x.h>
- #define MenuPage 3
- #define OLED_DC 6
- #define OLED_CS 9
- #define OLED_CLK 3
- #define OLED_MOSI 4
- #define OLED_RESET 5
- Adafruit_SSD1306 oled(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);
- #if (SSD1306_LCDHEIGHT != 64)
- #error("Height incorrect, please fix Adafruit_SSD1306.h!");
- #endif
- #define dataPin 10
- #define clockPin 11
- SHT1x sht1x(dataPin, clockPin);
- void DisplaySHT71(void)
- {
- float temp_c;
- float temp_f;
- float humidity;
- // Read values from the sensor
- temp_c = sht1x.readTemperatureC();
- temp_f = sht1x.readTemperatureF();
- humidity = sht1x.readHumidity();
-
- oled.setTextSize(1);
- oled.setTextColor(WHITE);
- oled.setCursor(0,8);
- oled.print("Temperature:");
- oled.setTextSize(2);
- oled.setCursor(0,16);
- oled.print(temp_c);
- oled.setTextSize(1);
- oled.setCursor(66,16);
- oled.print("C ");
- oled.setCursor(78,16);
- oled.print(temp_f);
- oled.setCursor(108,16);
- oled.print("F");
-
- oled.setCursor(0,40);
- oled.println("Humidity:");
- oled.setTextSize(2);
- oled.setCursor(0,48);
- oled.println(humidity);
- oled.setCursor(60,48);
- oled.print("%");
-
- oled.display();
- delay(50);
- oled.clearDisplay();
-
- }
- void setup()
- {
- oled.begin(SSD1306_SWITCHCAPVCC);
- oled.clearDisplay();
- oled.setTextColor(WHITE);
- }
- void loop()
- {
- DisplaySHT71();
- }
复制代码
附件是库和源程序,欢迎下载。
|