LoginSignup
0
0

More than 1 year has passed since last update.

Arduino UNOでセンサーの値を電圧で表示する。(浮動小数点使用)

Last updated at Posted at 2022-06-18

x いちおう書いておくがあまり「正確」じゃない ちょつとだいたいね~

目的
例題中例題で教科書的なプログラムを組んで電圧を見て「にぁにぁ」して遊ぶ。
なにが楽しいのかは、秘密。

o_con543.jpg

プログラムサイズ 3,174バイト

o_con544.jpg



//SER_Voltage_float_UNO_1

#include <Arduino.h>

//初期化処理
void setup()
{

  Serial.begin(9600); //シリアルポートの初期化

} //setup

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

  //センサーの値を読み込む
  int sensorValue = analogRead(A0); // UNO

  //int s = sensorValue;
  //int s = 82;   //debug
  //int s = 1024; //debug
  //Serial.print("Debug Voltage[");
  //Serial.print( ( (unsigned int)0b100111 * (unsigned int)s + (s >> 4 ) ) >> 3);
  //Serial.println("]");

  //センサーのADC値を電圧に変換
  float Voltage = sensorValue * ( 5.0 / 1024.0 );

  //電圧の表示
  Serial.print("Voltage = [");
  Serial.print(Voltage);
  Serial.print("]");
  Serial.println();

  //0.5秒の待ち
  delay(500);

} //loop


3.3V系 Arduino


  //センサーのADC値を電圧に変換
  float Voltage = sensorValue * ( 3.3 / 1024.0 );


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