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.

(UNO)センサーの値0...1023を0...約3.3Vに変換してあそぶ(3倍して15.625掛けて16で割り1/10足す)

Last updated at Posted at 2024-08-10

x 単位は、mV
x 軽量高速化、みやすさ重視
x Arduino UNO互換機

目的
ADCの結果を電圧に変換する。
小マイコン用に容量を減らす

いろいろ
適当にインターネット見ていると、基本は、
電圧変換は、単精度浮動小数を使うみたいな、
利用者の大多数が初心者でmVもシフト演算も
やっていなく、
ボリュームを回して喜ぶレベルだと?(はてな)が付く。

小ネタ

これも、マジックナンバーやーーー

15.625 = 2.5 x 2.5 x 2.5

4000 = 15.625 x 256

結果

o_coq307.jpg

プログラム

オンラインコンパイラ


//ADC_0__3_3_x15_UNO_1

//初期化
void setup() {

  //シリアルポート初期化とメッセージ
  Serial.begin(9600);
  Serial.println("START");

  int s; //センサーの値
  unsigned int vo; //電圧

  s = 1024; //センサーの値を1024

  //センサーの値から電圧に変換(x3 x15.625/16 1/10)
  vo = s;
  vo = vo + vo + vo;
  vo = ((vo * 15U) + (vo >> 1) + (vo >> 3)) >> 4;
  vo = vo + (vo / 10);

  //センサーの値と電圧を表示
  Serial.print(s);
  Serial.print(',');
  Serial.print((int)vo);
  Serial.println();

}//setup

//メインループ
void loop() {
}//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?