« Arduinoで作ろう(16) HC-SR04 で距離の測定 | トップページ | Arduinoで作ろう(18) LCD Keypad Shield を買ってみた »

2018年7月 1日 (日)

Arduinoで作ろう(17) MPL115A2で大気圧測定

Multifunctionshield_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);
}
}

| |

« Arduinoで作ろう(16) HC-SR04 で距離の測定 | トップページ | Arduinoで作ろう(18) LCD Keypad Shield を買ってみた »

Arduino」カテゴリの記事

コメント

コメントを書く



(ウェブ上には掲載しません)


コメントは記事投稿者が公開するまで表示されません。



トラックバック


この記事へのトラックバック一覧です: Arduinoで作ろう(17) MPL115A2で大気圧測定:

« Arduinoで作ろう(16) HC-SR04 で距離の測定 | トップページ | Arduinoで作ろう(18) LCD Keypad Shield を買ってみた »