7 segment
character LCD
HMI
OLED
Nokia LCD
e-ink
TV
byte segment_0[] = {1, 1, 1, 1, 1, 1, 0, 0};
byte segment_1[] = {0, 1, 1, 0, 0, 0, 0, 0};
byte segment_2[] = {1, 1, 0, 1, 1, 0, 1, 0};
byte segment_3[] = {1, 1, 1, 1, 0, 0, 1, 0};
byte segment_4[] = {0, 1, 1, 0, 0, 1, 1, 0};
byte segment_5[] = {1, 0, 1, 1, 0, 1, 1, 0};
byte segment_6[] = {1, 0, 1, 1, 1, 1, 1, 0};
byte segment_7[] = {1, 1, 1, 0, 0, 0, 0, 0};
byte segment_8[] = {1, 1, 1, 1, 1, 1, 1, 0};
byte segment_9[] = {1, 1, 1, 1, 0, 1, 1, 0};
void setup()
{
for (int i = 0; i<8; i++){
pinMode(i, OUTPUT);
}
}
void loop()
{
for (int i = 0; i<10; i++){
draw(i);
delay(1000);
}
}
void draw(int digit){
switch (digit) {
case 0:
for (int i = 0; i<8; i++){
digitalWrite(i, segment_0[i]);
}
break;
case 1:
for (int i = 0; i<8; i++){
digitalWrite(i, segment_1[i]);
}
break;
case 2:
for (int i = 0; i<8; i++){
digitalWrite(i, segment_2[i]);
}
break;
case 3:
for (int i = 0; i<8; i++){
digitalWrite(i, segment_3[i]);
}
break;
case 4:
for (int i = 0; i<8; i++){
digitalWrite(i, segment_4[i]);
}
break;
case 5:
for (int i = 0; i<8; i++){
digitalWrite(i, segment_5[i]);
}
break;
case 6:
for (int i = 0; i<8; i++){
digitalWrite(i, segment_6[i]);
}
break;
case 7:
for (int i = 0; i<8; i++){
digitalWrite(i, segment_7[i]);
}
break;
case 8:
for (int i = 0; i<8; i++){
digitalWrite(i, segment_8[i]);
}
break;
case 9:
for (int i = 0; i<8; i++){
digitalWrite(i, segment_9[i]);
}
break;
}}
Riadenie bez knižnice
#include "SevSeg.h"
SevSeg sevseg;
void setup(){
byte numDigits = 1;
byte digitPins[] = {};
byte segmentPins[] = {0, 1, 2, 3, 4, 5, 6, 7};
bool resistorsOnSegments = true;
byte hardwareConfig = COMMON_CATHODE;
sevseg.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments);
sevseg.setBrightness(90);
}
void loop(){
for(int i = 0; i < 10; i++){
sevseg.setNumber(i);
delay(1000);
sevseg.refreshDisplay();
}
}
Riadenie cez knižnicu SevSeg.h
https://github.com/DeanIsMe/SevSeg
Prevodník BCD -> 7 segment
https://www.elektrolab.eu/blog/rozdelenie-princip-a-funkcia-7-segmentoveho-displeja
PIN | Function | |
---|---|---|
1 | Vss | Ground Terminal |
2 | Vcc | Positive Supply |
3 | Vdd | Contrast adjustment |
4 | RS | Register Select; 0→Instruction Register, 1→Data Register |
5 | R/W | Read/write Signal; 1→Read, 0→ Write |
6 | E | Enable; Falling edge |
7 | DB0 | Bi-directional data bus |
8 | DB1 | |
9 | DB2 | |
10 | DB3 | |
11 | DB4 | |
12 | DB5 | |
13 | DB6 | |
14 | DB7 | |
15 | LED-(K) | Back light LED cathode terminal |
16 | LED+(A) | Back Light LED anode terminal |
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 8, 7, 1, 0);
void setup()
{
lcd.begin(16, 2);
}
void loop()
{
lcd.setCursor(0, 0);
lcd.print("Hello");
lcd.setCursor(0, 1);
lcd.print("Druhy riadok");
}
I2C Interface
#include <Wire.h> // Library for I2C communication
#include <LiquidCrystal_I2C.h> // Library for LCD
LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x27, 16, 2);
void setup() {
lcd.init();
lcd.backlight();
}
void loop() {
lcd.setCursor(2, 0);
lcd.print("Hello World!");
}
<LiquidCrystal_I2C.h>