「Arduino Mega 2560 LESSON:20 サウンドセンサーモジュール」の版間の差分
編集の要約なし タグ: 差し戻し済み |
編集の要約なし |
||
| (同じ利用者による、間の3版が非表示) | |||
| 66行目: | 66行目: | ||
== '''概要''' == | == '''概要''' == | ||
サウンドセンサーモジュールを接続するレッスンです。ただし部品がこわれているのか、声には反応せず、衝撃にしか反応しないです。これは深追いすると辛いことになるので、あきらめました。 | |||
| 87行目: | 87行目: | ||
AnalogInputコードは以下のようなものです。 | |||
<freescript></script><div class="hljs-wrap"><pre data-label="Arduino Code" class="pre-wrap"> | <freescript></script><div class="hljs-wrap"><pre data-label="Arduino Code" class="pre-wrap"> | ||
<code class="cpp"> | <code class="cpp">//www.elegoo.com | ||
//2016.12.9 | |||
int sensorPin = A0; // select the input pin for the potentiometer | |||
int ledPin = 13; // select the pin for the LED | |||
int sensorValue = 0; // variable to store the value coming from the sensor | |||
void setup() | |||
{ | |||
pinMode(ledPin,OUTPUT); | |||
Serial.begin(9600); | |||
} | |||
void loop(){ | |||
sensorValue = analogRead(sensorPin); | |||
digitalWrite(ledPin, HIGH); | |||
delay(sensorValue); | |||
digitalWrite(ledPin, LOW); | |||
delay(sensorValue); | |||
Serial.println(sensorValue, DEC); | |||
} | |||
</code></pre></div><script></freescript> | |||
DigitalInputコードは以下のようなものです。 | |||
<freescript></script><div class="hljs-wrap"><pre data-label="Arduino Code" class="pre-wrap"> | |||
<code class="cpp">//www.elegoo.com | |||
//2016.06.13 | |||
int Led=13;//define LED port | |||
int buttonpin=3; //define switch port | |||
;int val;//define digital variable val | |||
void setup() | |||
{ | |||
pinMode(Led,OUTPUT);//define LED as a output port | |||
pinMode(buttonpin,INPUT);//define switch as a output port | |||
} | |||
void loop() | |||
{ val=digitalRead(buttonpin);//read the value of the digital interface 3 assigned to val | |||
if(val==HIGH)//when the switch sensor have signal, LED blink | |||
{ | |||
digitalWrite(Led,HIGH); | |||
} | |||
else | |||
{ | |||
digitalWrite(Led,LOW); | |||
} | |||
} | |||
</code></pre></div><script></freescript> | </code></pre></div><script></freescript> | ||
[[Arduino Mega 2560]]に戻る。 | [[Arduino Mega 2560]]に戻る。 | ||
2026年10月29日 (木) 17:35時点における最新版
概要
サウンドセンサーモジュールを接続するレッスンです。ただし部品がこわれているのか、声には反応せず、衝撃にしか反応しないです。これは深追いすると辛いことになるので、あきらめました。
完成図は以下のとおりです。
[[|380px||none|完成図]]
PCB図は以下のようなものです。
[[|380px||none|PCB図]]
3Dプレビュー図は以下のようなものです。
[[|380px||none|3Dプレビュー図]]
AnalogInputコードは以下のようなものです。
//www.elegoo.com
//2016.12.9
int sensorPin = A0; // select the input pin for the potentiometer
int ledPin = 13; // select the pin for the LED
int sensorValue = 0; // variable to store the value coming from the sensor
void setup()
{
pinMode(ledPin,OUTPUT);
Serial.begin(9600);
}
void loop(){
sensorValue = analogRead(sensorPin);
digitalWrite(ledPin, HIGH);
delay(sensorValue);
digitalWrite(ledPin, LOW);
delay(sensorValue);
Serial.println(sensorValue, DEC);
}
DigitalInputコードは以下のようなものです。
//www.elegoo.com
//2016.06.13
int Led=13;//define LED port
int buttonpin=3; //define switch port
;int val;//define digital variable val
void setup()
{
pinMode(Led,OUTPUT);//define LED as a output port
pinMode(buttonpin,INPUT);//define switch as a output port
}
void loop()
{ val=digitalRead(buttonpin);//read the value of the digital interface 3 assigned to val
if(val==HIGH)//when the switch sensor have signal, LED blink
{
digitalWrite(Led,HIGH);
}
else
{
digitalWrite(Led,LOW);
}
}