LoginSignup
0
0

More than 1 year has passed since last update.

Arduino UNOのボリュームの入力でPWM出力

Last updated at Posted at 2022-06-18

目的
教科書的プログラムを書いて遊ぶ
一部教科書から逸脱した毒も込み(2ビット右シフト)

o_con545.jpg

o_con546.jpg


//PWM_ Potentiometer_UNO_1

#include <Arduino.h>

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

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

} //setup

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

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

  //センサーのADC値をPWMの値に変換
  int outputValue = map(sensorValue, 0, 1024, 0, 256);

  //Debug
  //int outputValue = sensorValue >> 2;

  //PWMの出力
  analogWrite( 5 , outputValue );

  //PWMの値の表示
  Serial.print("PWM = [");
  Serial.print(outputValue);
  Serial.print("]");
  Serial.println();

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

} //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