#include "funshield.h" constexpr int digit_positions = sizeof(digit_muxpos) / sizeof(digit_muxpos[0]); void writeGlyphBitmask( byte glyph, byte pos_bitmask) { digitalWrite( latch_pin, LOW); shiftOut( data_pin, clock_pin, MSBFIRST, glyph); shiftOut( data_pin, clock_pin, MSBFIRST, pos_bitmask); digitalWrite( latch_pin, HIGH); } void writeGlyphR(byte glyph, int pos) { writeGlyphBitmask(glyph, digit_muxpos[digit_positions - pos - 1]); } void writeGlyphL(byte glyph, int pos) { writeGlyphBitmask(glyph, digit_muxpos[pos]); } void writeDigit(int n, int pos) { writeGlyphR(digits[n], pos); } enum LedState {PRESSED, RELEASED}; class ButtonPresser { public: ButtonPresser(int pin) { pin_ = pin; } bool pressedOnce(bool button_pressed) { if (button_pressed == false) { prev_state_ = RELEASED; return false; } if (prev_state_ == PRESSED && button_pressed) return false; prev_state_ = PRESSED; return true; } private: LedState prev_state_ = RELEASED; int pin_; }; void setup() { pinMode(latch_pin, OUTPUT); pinMode(data_pin, OUTPUT); pinMode(clock_pin, OUTPUT); } constexpr int buttons[] = { button1_pin, button2_pin, button3_pin }; ButtonPresser pressers[] { ButtonPresser(button1_pin), ButtonPresser(button2_pin), ButtonPresser(button3_pin) }; int citac = 0; int pozicia = 0; void loop() { // put your main code here, to run repeatedly: if ( pressers[0].pressedOnce(!digitalRead(buttons[0]))) citac += 1; if (pressers[1].pressedOnce(!digitalRead(buttons[1]))) citac += 9; if (pressers[2].pressedOnce(!digitalRead(buttons[2]))) pozicia +=1; pozicia %=4; citac %= 10; writeDigit(citac, pozicia); } ###################################SERIAL READ################################### #include "funshield.h" constexpr int digit_positions = sizeof(digit_muxpos) / sizeof(digit_muxpos[0]); void writeGlyphBitmask( byte glyph, byte pos_bitmask) { digitalWrite( latch_pin, LOW); shiftOut( data_pin, clock_pin, MSBFIRST, glyph); shiftOut( data_pin, clock_pin, MSBFIRST, pos_bitmask); digitalWrite( latch_pin, HIGH); } void writeGlyphR(byte glyph, int pos) { writeGlyphBitmask(glyph, digit_muxpos[digit_positions - pos - 1]); } void writeGlyphL(byte glyph, int pos) { writeGlyphBitmask(glyph, digit_muxpos[pos]); } void writeDigit(int n, int pos) { writeGlyphR(digits[n], pos); } void setup() { Serial.begin(9600); pinMode(latch_pin, OUTPUT); pinMode(data_pin, OUTPUT); pinMode(clock_pin, OUTPUT); } void loop() { if (Serial.available() > 0) { int incomingByte = Serial.read(); int cislo = incomingByte - '0'; Serial.println(cislo); writeDigit(cislo, digit_muxpos[1]); } } ###################################DEBUG PRINT################################### // pouzitie: // d_print("Teraz vypisem premennu FFF ", FFF, " a aby som odriadkoval, napisem newline \n."); #define DEBUG 1 // nastav na 0, aby si zakazal debug print template void d_print(Arg arg) { #if DEBUG Serial.print(arg); #endif } template void d_print(Arg arg, Rest... rest) { #if DEBUG d_print(arg); d_print(rest...); #endif }