Arduinoで作ろう(17) MPL115A2で大気圧測定
Multi Function Shield にI2C接続の大気圧センサ MPL115A2 をつないで大気圧計にしてみました。
前回LCDに表示させてたやつの7セグLED版です。
スケッチはこちら→ 20180701MPL115A2.ino
/* Multi_function_shield 大気圧センサ MPL115A2 */#include <Wire.h>
#include <MPL115A2.h>
const int LAT = 4; // Latchピン
const int CLK = 7; // Clockピン
const int SDI = 8; // Serial Data In ピン
int pressure;
int Buffer[4] = {0}; //1~4桁 数字のバッファbyte digit[10] = //7seg 点灯パターン
{
B00000011, // 数字 0
B10011111, // 1
B00100101, // 2
B00001101, // 3
B10011001, // 4
B01001001, // 5
B01000001, // 6
B00011011, // 7
B00000001, // 8
B00001001 // 9
};const byte keta[4] =
{
B00010000, //1桁め
B00100000, //2桁め
B01000000, //3桁め
B10000000 //4桁め
};void setup() {
pinMode(SDI, OUTPUT);
pinMode(CLK, OUTPUT);
pinMode(LAT, OUTPUT);
MPL115A2.begin();
//Serial.begin(9600);
}void loop() {
pressure = MPL115A2.read();
//Serial.println(pressure);
Buffer[3] = int(pressure) / 1000;
Buffer[2] = (int(pressure) % 1000) / 100;
Buffer[1] = (int(pressure) % 100) / 10;
Buffer[0] = (int(pressure) % 100) % 10;
Disp();
}void Disp() {
for (byte j = 0; j < 4; j++) {
digitalWrite(LAT, LOW);
shiftOut(SDI, CLK, LSBFIRST, digit[Buffer[j]]);
shiftOut(SDI, CLK, LSBFIRST, keta[j]); // 桁
digitalWrite(LAT, HIGH);
delay(4);
}
}
| 固定リンク | 0
「Arduino」カテゴリの記事
- WCH-LinkE とWCH-Link は別モノである(2023.12.02)
- Arduinoで作ろう(63) UNO R4 WiFiでスクロールNTP時計(2023.12.01)
- Arduinoで作ろう(62) ESP8266+SSD1306でNTP時計(2023.11.18)
- 新型 Arduino UNO R4 MINIMA を買った(2023.07.01)
コメント