Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define D0 7
- #define D1 6
- #define D2 5
- #define D3 4
- #define D4 3
- #define D5 2
- #define D6 1
- #define D7 0
- #define A 8
- #define B 9
- #define C 10
- #define D 11
- #define E 12
- #define F_SEG 13
- #define G 14
- #define CA1 15
- #define CA2 16
- const int vstup[8] = {D0, D1, D2, D3, D4, D5, D6, D7};
- const byte numbers[16] = { 0b1000000, 0b1111001, 0b0100100, 0b0110000, 0b0011001, 0b0010010, 0b0000010, 0b1111000, 0b0000000, 0b0010000, 0b0001000, 0b0000011, 0b1000110, 0b0100001, 0b0000110, 0b0001110};
- const int segs[7] = { A, B, C, D, E, F_SEG, G };
- byte cislo;
- void setup() {
- for (int i = 0; i < 7; i++) {
- pinMode(segs[i], OUTPUT);
- }
- // pinMode(A, OUTPUT);
- // pinMode(B, OUTPUT);
- // pinMode(C, OUTPUT);
- // pinMode(D, OUTPUT);
- // pinMode(E, OUTPUT);
- // pinMode(F_SEG, OUTPUT);
- // pinMode(G, OUTPUT);
- pinMode(CA1, OUTPUT);
- pinMode(CA2, OUTPUT);
- for (int i = 0; i < 8; i++) {
- pinMode(vstup[i], INPUT);
- //digitalWrite(vstup[i], HIGH);
- }
- // pinMode(D0, INPUT);
- // pinMode(D1, INPUT);
- // pinMode(D2, INPUT);
- // pinMode(D3, INPUT);
- // pinMode(D4, INPUT);
- // pinMode(D5, INPUT);
- // pinMode(D6, INPUT);
- // pinMode(D7, INPUT);
- // digitalWrite(D0, HIGH);
- // digitalWrite(D1, HIGH);
- // digitalWrite(D2, HIGH);
- // digitalWrite(D3, HIGH);
- // digitalWrite(D4, HIGH);
- // digitalWrite(D5, HIGH);
- // digitalWrite(D6, HIGH);
- // digitalWrite(D7, HIGH);
- // Serial.begin(9600);
- // Serial.println("jedeme");
- }
- void loop() {
- for (int i = 0; i < 4; i++) {
- bitWrite(cislo, i, digitalRead(vstup[i]));
- }
- lightDigit1(numbers[cislo]);
- delay(10);
- for (int i = 0; i < 4; i++) {
- bitWrite(cislo, i, digitalRead(vstup[i + 4]));
- }
- lightDigit2(numbers[cislo]);
- delay(10);
- // Serial.println(cislo, HEX);
- // delay(500);
- }
- void lightDigit1(byte number) {
- digitalWrite(CA1, LOW);
- digitalWrite(CA2, HIGH);
- lightSegments(number);
- }
- void lightDigit2(byte number) {
- digitalWrite(CA1, HIGH);
- digitalWrite(CA2, LOW);
- lightSegments(number);
- }
- void lightSegments(byte number) {
- for (int i = 0; i < 7; i++) {
- int bit = bitRead(number, i);
- digitalWrite(segs[i], bit);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement