1气压计
#include <Adafruit_BMP085.h> Adafruit_BMP085 bmp; void setup() { Serial.begin(9600); if (!bmp.begin()) { Serial.println("Could not find a valid BMP085 sensor, check wiring!"); while (1) {} } } void loop() { int Pressure=bmp.readPressure(); float Altitude=bmp.readAltitude(); String Msg="Pressure = "+String(Pressure)+"pa Altitude = "+String(Altitude)+"M"; Serial.println(Msg); delay(500); }
2显示器
#include <SPI.h> #include <Wire.h> #include <Adafruit_GFX.h> #include <Adafruit_SSD1306.h> Adafruit_SSD1306 display = Adafruit_SSD1306(128, 32, &Wire); void setup() { Serial.begin(9600); Serial.println("OLED FeatherWing test"); // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // Address 0x3C for 128x32 Serial.println("OLED begun"); display.display(); delay(1000); // Clear the buffer. display.clearDisplay(); display.display(); Serial.println("IO test"); // text display tests display.setTextSize(1); display.setTextColor(SSD1306_WHITE); display.setCursor(0,0); display.print("Connecting to SSID\n'adafruit':"); display.print("connected!"); display.println("IP: 10.0.1.23"); display.println("Sending val #0"); display.setCursor(0,0); display.display(); // actually display all of the above } void loop() { delay(10); yield(); display.display(); }
3 总代码
#include <SPI.h> #include <Wire.h> #include <Adafruit_GFX.h> #include <Adafruit_SSD1306.h> Adafruit_SSD1306 display = Adafruit_SSD1306(128, 32, &Wire); #include <Adafruit_BMP085.h> Adafruit_BMP085 bmp; void setup() { Serial.begin(9600); if (!bmp.begin()) { Serial.println("Could not find a valid BMP085 sensor, check wiring!"); } int Pressure=bmp.readPressure(); float Altitude=bmp.readAltitude(); String Msg="Pressure = "+String(Pressure)+"pa Altitude = "+String(Altitude)+"M"; Serial.println(Msg); Serial.println("OLED FeatherWing test"); display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // Address 0x3C for 128x32 Serial.println("OLED begun"); // Clear the buffer. display.clearDisplay(); display.display(); delay(1000); Serial.println("IO test"); display.clearDisplay(); delay(3); display.setTextSize(1); display.setTextColor(SSD1306_WHITE); display.setCursor(0,0); display.print(Pressure);display.println("Pa"); display.print(Altitude);display.println("M"); display.display(); // actually display all of the above delay(100); } void loop() { //yield(); display.clearDisplay(); delay(10); int Pressure=bmp.readPressure(); float Altitude=bmp.readAltitude(); display.setTextSize(1); display.setTextColor(SSD1306_WHITE); display.setCursor(0,0); display.print(Pressure);display.println("Pa"); display.print(Altitude);display.println("M"); display.display(); delay(10); }