「Arduino Mega 2560 LESSON:27 74HC595 と 7セグメント」の版間の差分
(ページの作成:「<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;…」) |
編集の要約なし |
||
| (同じ利用者による、間の3版が非表示) | |||
| 66行目: | 66行目: | ||
== '''概要''' == | == '''概要''' == | ||
74HC595 と7セグメントLEDを接続するレッスンです。 | |||
完成図は以下のとおりです。 | |||
[[ファイル:Mega2560 L27 01 完成図.jpg|380px||none|完成図]] | |||
PCB図は以下のようなものです。 | |||
[[ファイル:Mega2560 L27 02 PCB図.png|380px||none|PCB図]] | |||
3Dプレビュー図は以下のようなものです。 | |||
[[ファイル:Mega2560 L27 03 3DPreview図.png|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.12 | |||
// define the LED digit patterns, from 0 - 9 | |||
// 1 = LED on, 0 = LED off, in this order: | |||
// 74HC595 pin Q0,Q1,Q2,Q3,Q4,Q5,Q6,Q7 | |||
// Mapping to a,b,c,d,e,f,g of Seven-Segment LED | |||
byte seven_seg_digits[10] = { B11111100, // = 0 | |||
B01100000, // = 1 | |||
B11011010, // = 2 | |||
B11110010, // = 3 | |||
B01100110, // = 4 | |||
B10110110, // = 5 | |||
B10111110, // = 6 | |||
B11100000, // = 7 | |||
B11111110, // = 8 | |||
B11100110 // = 9 | |||
}; | |||
// connect to the ST_CP of 74HC595 (pin 3,latch pin) | |||
int latchPin = 3; | |||
// connect to the SH_CP of 74HC595 (pin 4, clock pin) | |||
int clockPin = 4; | |||
// connect to the DS of 74HC595 (pin 2) | |||
int dataPin = 2; | |||
void setup() { | |||
// Set latchPin, clockPin, dataPin as output | |||
pinMode(latchPin, OUTPUT); | |||
pinMode(clockPin, OUTPUT); | |||
pinMode(dataPin, OUTPUT); | |||
} | |||
// display a number on the digital segment display | |||
void sevenSegWrite(byte digit) { | |||
// set the latchPin to low potential, before sending data | |||
digitalWrite(latchPin, LOW); | |||
// the original data (bit pattern) | |||
shiftOut(dataPin, clockPin, LSBFIRST, seven_seg_digits[digit]); | |||
// set the latchPin to high potential, after sending data | |||
digitalWrite(latchPin, HIGH); | |||
} | |||
void loop() { | |||
// count from 9 to 0 | |||
for (byte digit = 10; digit > 0; --digit) { | |||
delay(1000); | |||
sevenSegWrite(digit - 1); | |||
} | |||
// suspend 4 seconds | |||
delay(1000); | |||
} | |||
</code></pre></div><script></freescript> | </code></pre></div><script></freescript> | ||
2026年11月7日 (土) 00:41時点における最新版
概要
74HC595 と7セグメントLEDを接続するレッスンです。
完成図は以下のとおりです。
PCB図は以下のようなものです。
3Dプレビュー図は以下のようなものです。
コードは以下のようなものです。
//www.elegoo.com
//2016.12.12
// define the LED digit patterns, from 0 - 9
// 1 = LED on, 0 = LED off, in this order:
// 74HC595 pin Q0,Q1,Q2,Q3,Q4,Q5,Q6,Q7
// Mapping to a,b,c,d,e,f,g of Seven-Segment LED
byte seven_seg_digits[10] = { B11111100, // = 0
B01100000, // = 1
B11011010, // = 2
B11110010, // = 3
B01100110, // = 4
B10110110, // = 5
B10111110, // = 6
B11100000, // = 7
B11111110, // = 8
B11100110 // = 9
};
// connect to the ST_CP of 74HC595 (pin 3,latch pin)
int latchPin = 3;
// connect to the SH_CP of 74HC595 (pin 4, clock pin)
int clockPin = 4;
// connect to the DS of 74HC595 (pin 2)
int dataPin = 2;
void setup() {
// Set latchPin, clockPin, dataPin as output
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
}
// display a number on the digital segment display
void sevenSegWrite(byte digit) {
// set the latchPin to low potential, before sending data
digitalWrite(latchPin, LOW);
// the original data (bit pattern)
shiftOut(dataPin, clockPin, LSBFIRST, seven_seg_digits[digit]);
// set the latchPin to high potential, after sending data
digitalWrite(latchPin, HIGH);
}
void loop() {
// count from 9 to 0
for (byte digit = 10; digit > 0; --digit) {
delay(1000);
sevenSegWrite(digit - 1);
}
// suspend 4 seconds
delay(1000);
}