Připojení k Arduinu
| Pin DL-340M | Název pinu DL-340M | Pin Arduino |
|---|
| 1 | – | – |
| 2 | E | D6 (přes odpor 220ohm) |
| 3 | D | D5 (přes odpor 220ohm) |
| 4 | C | D4 (přes odpor 220ohm) |
| 5 | DP | A0 (přes odpor 1kohm) |
| 6 | G | D8 (přes odpor 220ohm) |
| 7 | CATHODE 4 | D12 |
| 8 | – | – |
| 9 | B | D3 (přes odpor 220ohm) |
| 10 | CATHODE 3 | D11 |
| 11 | F | D7 (přes odpor 220ohm) |
| 12 | CATHODE 2 | D10 |
| 13 | A | D2 (přes odpor 220ohm) |
| 14 | CATHODE 1 | D9 |
Zdrojový kód pro Arduino
#include "SevSeg.h"
SevSeg sevseg;
byte numDigits = 4;
byte digitPins[] = {9, 10, 11, 12};
byte segmentPins[] = {2, 3, 4, 5, 6, 7, 8, A0};
bool resistorsOnSegments = false;
byte hardwareConfig = COMMON_CATHODE;
bool updateWithDelays = false;
bool leadingZeros = true;
void setup() {
sevseg.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments, updateWithDelays, leadingZeros);
sevseg.setBrightness(40);
}
void loop() {
static unsigned long timer = millis();
static int deciSeconds = 0;
static byte deciPoint = 0;
if (millis() - timer >= 100) {
timer += 100;
deciSeconds++;
deciPoint++;
if (deciPoint == numDigits) {
deciPoint = 0;
}
if (deciSeconds == pow(10, numDigits)) {
deciSeconds = 0;
}
sevseg.setNumber(deciSeconds, deciPoint);
}
sevseg.refreshDisplay();
}
Demo video