0
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?

More than 1 year has passed since last update.

X-NUCLEO-GFX01M1で温度計を作る改(マクロ変換)(MCP9701)(STM32G071)(ILI9341)

Last updated at Posted at 2024-01-25

x MCP9701-E/TO 販売コード 103199

X-NUCLEO-GFX01M1で温度計を作る改(マクロ変換)(MCP9701)(STM32G071)(ILI9341)

Arduino ILI9341 MCP9701 STM32G071 X-NUCLEO-GFX01M1

x 過去ログを見よ とりまarduinoのところにいろいろある

目的
テキストのテスト
A2に温度センサーを接続した。
変換をマクロ化した。
小数点を0,.25,.50,.75に丸めた
25で割って25で掛けると丸められる(20240125)

o_cop892.jpg



//ili9341_mcp9701_071_3

//インクルド
#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"


//100の割り算 0から30000までは、だいたい正しい   
#define DIV100(in) ((in*(65536/100*64+24))>>22)
//25の割り算 0から30000までは、だいたい正しい   
#define DIV25(in) ((in*(65536/25*16+8))>>20)
//MCP9701の温度を求める x100
#define TMP(so) ((((so)*270769)-134432821)>>16)


//設定
#define TFT_RST 54 //A1
#define TFT_DC 3
#define TFT_CS 4

//液晶の定義
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);


//初期化
void setup() {

  //シリアルの初期化
  Serial.begin(9600);
  Serial.println("ILI9341 Test!"); 

  //液晶の初期化
  tft.begin();

  //画面のクリア
  tft.fillScreen(ILI9341_BLACK);
  
}//setup


//無限ループ
void loop(void) {


  //センサーの値を読み込む
  analogReadResolution(12); // ADC 12bit mode
  int s = analogRead(A2);   // センサーの読み取り値
  
  //センサーの値を温度に変換
  int t = TMP(s);
  int d1 = DIV100(t);
  int d01 = (t - (d1 * 100));d01 = (DIV25(d01))*25;
  

  //温度の表示

  //クリア
  tft.fillRect( 0 ,0 , 24*5 , 24 , ILI9341_BLACK);

  //表示位置を0,0にする
  tft.setCursor(0, 0);

  //テキストの表示
  tft.setTextColor(ILI9341_WHITE);
  tft.setTextSize(3);
  tft.print(" ");
  tft.print(d1);
  tft.print(".");
  if( d01 >= 0 && d01 <= 9 ) { tft.print("0"); }
  tft.print(d01);
  tft.print(" ");
  
  delay(1000); //1秒待つ

}//loop


0
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
0
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?