回答例
LEDアレイに温度を表示するサンプルです。
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 |
#include <LSM303AGR_ACC_Sensor.h> #include <Adafruit_Microbit.h> #include <stdio.h> #define DEV_I2C Wire #define SerialPort Serial LSM303AGR_ACC_Sensor Acc(&DEV_I2C); Adafruit_Microbit_Matrix microbit; void setup() { SerialPort.begin(9600); DEV_I2C.begin(); Acc.begin(); Acc.Enable(); Acc.EnableTemperatureSensor(); microbit.begin(); } void loop() { // Read accelerometer LSM303AGR. int32_t accelerometer[3]; Acc.GetAxes(accelerometer); // Read temperature LSM303AGR. float temperature; Acc.GetTemperature(&temperature); // Output data. SerialPort.print(" | Temp[C]: "); SerialPort.print(temperature, 2); SerialPort.println(" |"); // Display data. char str[80]; sprintf(str, "%.1f C", temperature); microbit.print(str); delay(200); } |