1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

(SSD1327)M5NanoC6で加速度(ADXL345)を表示して遊ぶ。

Last updated at Posted at 2024-10-06

x 過去ログを見よ
x Adafruit_ADXL345をインストール
x Adafruit_GFX,Adafruit_SSD1327をインストール

目的
加速度センサーで遊ぶ

結果

o_coq492.jpg

プログラム



//ssd1327_ADXL345_test1_M6NanoC6_1


//ヘッダーファイル
#include <Arduino.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1327.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_ADXL345_U.h>
#define ESP8266 1


//定義
#define SCREEN_WIDTH  128   // OLED display width, in pixels
#define SCREEN_HEIGHT 96    // OLED display height, in pixels
#define OLED_RESET     -1   // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1327 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

#define setCursorAA(AA,BB) setCursor(AA+16,BB)

/* Assign a unique ID to this sensor at the same time */
Adafruit_ADXL345_Unified accel = Adafruit_ADXL345_Unified(12345);


//初期化
void setup() {

  // I2Cアドレスは使用するディスプレイに合わせて変更する
  display.begin(SCREEN_ADDRESS);

  // 画面表示をクリア
  display.clearDisplay();

  // テキストサイズを設定
  display.setTextSize(1);
  // テキスト色を設定
  display.setTextColor(SSD1327_WHITE);

  // テキストの開始位置を設定 メッセージの表示
  display.setCursorAA(0, 16);
  display.println("Accelerometer");
  display.setCursorAA(0, 16+8);
  display.println("Test");
  // 描画バッファの内容を画面に表示
  display.display();
  delay(500); //0.5秒待つ
  
  /* Initialise the sensor */
  if(!accel.begin()){
    /* There was a problem detecting the ADXL345 ... check your connections */

    // テキストの開始位置を設定 メッセージの表示
    display.setCursorAA(0, 32);
    display.println("Ooops,no ADXL345");
    display.setCursorAA(0, 32+8);
    display.println("detected ...");


    // テキストの開始位置を設定 メッセージの表示
    display.setCursorAA(0, 48);
    display.println("Check your");
    display.setCursorAA(0, 48+8);
    display.println("wiring!");

    // 描画バッファの内容を画面に表示
    display.display();

    while(1){delay(1);};//無限ループ
  }//endif

  /* Set the range to whatever is appropriate for your project */
  accel.setRange(ADXL345_RANGE_16_G);

}//setup


//メインループ
void loop() {

  // 画面表示をクリア
  display.clearDisplay();

  // テキストサイズを設定
  display.setTextSize(3);
  // テキスト色を設定
  display.setTextColor(SSD1327_WHITE);
  // テキストの開始位置を設定
  //display.setCursorAA(0, 16);


  /* Get a new sensor event */ 
  sensors_event_t event; 
  accel.getEvent(&event);

  /* Display the results (acceleration is measured in m/s^2) */

  // テキストの開始位置を設定 メッセージの表示
  display.setCursorAA(0, 0);
  display.println(event.acceleration.x);

  // テキストの開始位置を設定 メッセージの表示
  display.setCursorAA(0, 32);
  display.println(event.acceleration.y);

  // テキストの開始位置を設定 メッセージの表示
  display.setCursorAA(0, 64);
  display.println(event.acceleration.z);


  // 描画バッファの内容を画面に表示
  display.display();

  delay(500); //0.5秒待つ

}//loop


1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?