Last active
December 16, 2015 03:49
-
-
Save myy/5372495 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// cdsセルから読み取った値に応じて,ブザーの音程(発音)を制御するスケッチ | |
// ifで条件式を増やすことで,音程制御ができるようになる(はず) | |
// cdsセルから読み取った値が大きい→暗め | |
// cdsセルから読み取った値が小さい→明るめ | |
#include "pitches.h" | |
int val = 0; // アナログセンサから読み取った値用の変数 | |
int inputPin = 0; // 入力センサのピン番号 | |
int outputPin = 13; // 出力のピン番号 | |
void setup() { | |
Serial.begin(9600); // シリアルポートひらく | |
pinMode(outputPin, OUTPUT); // outputPinで設定したピン番号を出力モードにする | |
} | |
void loop() { | |
val = analogRead(inputPin); // 入力センサの値を読み取る | |
Serial.println(val); // シリアルモニタに読み取った値を出力する | |
if(val < 200) { | |
// 読み取った値が条件式の値以下のとき | |
tone(outputPin, NOTE_A4); | |
} else { | |
// そうでないとき | |
//tone(outputPin, NOTE_A5); | |
digitalWrite(outputPin, LOW); // 音を止めたい場合には,こう書けばよい | |
} | |
delay(300); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment