「Arduino Mega 2560 LESSON:26 光抵抗素子 PhotoCell」の版間の差分
(ページの作成:「<yjavascript></script> <script> // 最初に実行されるスクリプト document.addEventListener('DOMContentLoaded', () => { const observer = new MutationObserver((mutations) => { mutations.forEach((mutation) => { mutation.addedNodes.forEach((node) => { if (node.tagName === 'SCRIPT' &@@& node.textContent) { // JavaScriptコードを変換 const originalCode = node.textContent;…」) |
編集の要約なし |
||
| 66行目: | 66行目: | ||
== '''概要''' == | == '''概要''' == | ||
74HC595 と8個の LEDと光抵抗素子を接続するレッスンです。 | |||
完成図は以下のとおりです。 | |||
[[|380px||none|完成図]] | |||
PCB図は以下のようなものです。 | |||
[[|380px||none|PCB図]] | |||
3Dプレビュー図は以下のようなものです。 | |||
[[|380px||none|3Dプレビュー図]] | |||
コードは以下のようなものです。 | |||
<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 lightPin = 0; | |||
int latchPin = 11; | |||
int clockPin = 9; | |||
int dataPin = 12; | |||
int leds = 0; | |||
void setup() | |||
{ | |||
pinMode(latchPin, OUTPUT); | |||
pinMode(dataPin, OUTPUT); | |||
pinMode(clockPin, OUTPUT); | |||
} | |||
void updateShiftRegister() | |||
{ | |||
digitalWrite(latchPin, LOW); | |||
shiftOut(dataPin, clockPin, LSBFIRST, leds); | |||
digitalWrite(latchPin, HIGH); | |||
} | |||
void loop() | |||
{ | |||
int reading = analogRead(lightPin); | |||
int numLEDSLit = reading / 57; //1023 / 9 / 2 | |||
if (numLEDSLit > 8) numLEDSLit = 8; | |||
leds = 0; // no LEDs lit to start | |||
for (int i = 0; i < numLEDSLit; i++) | |||
{ | |||
leds = leds + (1 << i); // sets the i'th bit | |||
} | |||
updateShiftRegister(); | |||
} | |||
</code></pre></div><script></freescript> | </code></pre></div><script></freescript> | ||
2026年11月6日 (金) 17:39時点における版
概要
74HC595 と8個の LEDと光抵抗素子を接続するレッスンです。
完成図は以下のとおりです。
[[|380px||none|完成図]]
PCB図は以下のようなものです。
[[|380px||none|PCB図]]
3Dプレビュー図は以下のようなものです。
[[|380px||none|3Dプレビュー図]]
コードは以下のようなものです。
//www.elegoo.com
//2016.12.9
int lightPin = 0;
int latchPin = 11;
int clockPin = 9;
int dataPin = 12;
int leds = 0;
void setup()
{
pinMode(latchPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
}
void updateShiftRegister()
{
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, leds);
digitalWrite(latchPin, HIGH);
}
void loop()
{
int reading = analogRead(lightPin);
int numLEDSLit = reading / 57; //1023 / 9 / 2
if (numLEDSLit > 8) numLEDSLit = 8;
leds = 0; // no LEDs lit to start
for (int i = 0; i < numLEDSLit; i++)
{
leds = leds + (1 << i); // sets the i'th bit
}
updateShiftRegister();
}