#include "funshield.h" #include "string.h" // map of letter glyphs constexpr byte LETTER_GLYPH[] { 0b10001000, // A 0b10000011, // b 0b11000110, // C 0b10100001, // d 0b10000110, // E 0b10001110, // F 0b10000010, // G 0b10001001, // H 0b11111001, // I 0b11100001, // J 0b10000101, // K 0b11000111, // L 0b11001000, // M 0b10101011, // n 0b10100011, // o 0b10001100, // P 0b10011000, // q 0b10101111, // r 0b10010010, // S 0b10000111, // t 0b11000001, // U 0b11100011, // v 0b10000001, // W 0b10110110, // ksi 0b10010001, // Y 0b10100100, // Z }; constexpr byte EMPTY_GLYPH = 0b11111111; constexpr int positionsCount = 4; constexpr unsigned int scrollingInterval = 300; void displayChar(char ch, byte pos) { byte glyph; if (isAlpha(ch)) { glyph = LETTER_GLYPH[ ch - (isUpperCase(ch) ? 'A' : 'a') ]; } else if (isDigit(ch)) { glyph = digits[ch - '0']; } else { glyph = EMPTY_GLYPH; } digitalWrite(latch_pin, LOW); shiftOut(data_pin, clock_pin, MSBFIRST, glyph); shiftOut(data_pin, clock_pin, MSBFIRST, 1 << pos); digitalWrite(latch_pin, HIGH); } const char* message = "Ahoj"; class Display { public: void loop() { int message_len = strlen(message); char c = pozicia_ < message_len ? message[pozicia_] : ' '; displayChar(c, pozicia_); pozicia_++; pozicia_ %= 4; } private: int pozicia_ = 0; }; void setup() { pinMode(latch_pin, OUTPUT); pinMode(clock_pin, OUTPUT); pinMode(data_pin, OUTPUT); } Display d; void loop() { d.loop(); } ///////////////////////////////////////////POINTER & ARRAY/////////////////////////////////////// #include #include constexpr char* str_ptr = "Ahoj"; // A | h | o | j | '\0' // ^ | ^ //str_ptr|str_ptr+1 const char str_arr[5] {'A', 'h', 'o', 'j', '\0'}; const size_t size_arr = sizeof(str_arr); // 5 -> 5 prvkov velkosti 1B const size_t size_ptr = sizeof(str_ptr); // 8 -> velkost adresy na ktoru pointer ukazuje const char c1 = *str_ptr; // 'A' const char c2 = str_arr[0]; // 'A' const char c3 = *(str_ptr + 1); // 'h' const char c4 = str_ptr[1]; // 'h' int mystrlen(const char* s) { int i = 0; while(*s++) ++i; return i; } const char* str1 = "Ahoj1"; const char* str2 = "Ahoj2123"; int main() { str1 = str2; // str1 ukazuje teraz na rovnake miesto v pamati ako str2, teda na "Ahoj2123" const char* str = str1; int str_size = strlen(str); int mystr_size = mystrlen(str); printf("String size from strlen is %d\n", str_size); printf("String size from mystrlen is %d\n", mystr_size); }