test.zip
(13.23 KB)
授人以渔,不授人以鱼。
#include <Windows.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <conio.h> #include "tools.h" #include "LED.h" HANDLE Console_Output = GetStdHandle(STD_OUTPUT_HANDLE); int main(void) { SetConsoleTitleA("七段管演示"); const char* tips = "Press any key..."; const char* message = "請輸入需要顯示的數字(直接按<Enter>鍵結束程序):"; COORD pos; char buffer[81]; do { ClearScreen(); pos.X = 0; pos.Y = 0; Say(message, pos); GotoXY((SHORT)strlen(message) + 1, pos.Y); if (gets_s(buffer, _countof(buffer)) && (buffer[0] != '\0')) { int number = atoi(buffer); sprintf_s(buffer, "%u", number); SHORT length = (SHORT)strlen(buffer); for (SHORT index = 0; index < length; ++index) { LED_On(buffer[index] - '0', 1 + index * (LED_Width + 1), 5); // 向指定組輸出一位數字 } pos.X = 0; pos.Y = 24; Say(tips, pos); GotoXY((SHORT)strlen(tips), pos.Y); _getch(); } } while (buffer[0] != '\0'); return EXIT_SUCCESS; }
static const WORD Light[10][4] { // 0 { COMMON_LVB_GRID_HORIZONTAL + COMMON_LVB_GRID_LVERTICAL, COMMON_LVB_GRID_HORIZONTAL + COMMON_LVB_GRID_RVERTICAL, COMMON_LVB_UNDERSCORE + COMMON_LVB_GRID_LVERTICAL, COMMON_LVB_UNDERSCORE + COMMON_LVB_GRID_RVERTICAL }, // 1 { 0, COMMON_LVB_GRID_RVERTICAL, 0, COMMON_LVB_GRID_RVERTICAL }, // 2 { COMMON_LVB_GRID_HORIZONTAL, COMMON_LVB_GRID_HORIZONTAL + COMMON_LVB_GRID_RVERTICAL, COMMON_LVB_GRID_HORIZONTAL + COMMON_LVB_UNDERSCORE + COMMON_LVB_GRID_LVERTICAL, COMMON_LVB_GRID_HORIZONTAL + COMMON_LVB_UNDERSCORE }, // 3 { COMMON_LVB_GRID_HORIZONTAL, COMMON_LVB_GRID_HORIZONTAL + COMMON_LVB_GRID_RVERTICAL, COMMON_LVB_GRID_HORIZONTAL + COMMON_LVB_UNDERSCORE, COMMON_LVB_GRID_HORIZONTAL + COMMON_LVB_UNDERSCORE + COMMON_LVB_GRID_RVERTICAL }, // 4 { COMMON_LVB_GRID_LVERTICAL, COMMON_LVB_GRID_RVERTICAL, COMMON_LVB_GRID_HORIZONTAL, COMMON_LVB_GRID_HORIZONTAL + COMMON_LVB_GRID_RVERTICAL }, // 5 { COMMON_LVB_GRID_HORIZONTAL + COMMON_LVB_GRID_LVERTICAL, COMMON_LVB_GRID_HORIZONTAL, COMMON_LVB_GRID_HORIZONTAL + COMMON_LVB_UNDERSCORE, COMMON_LVB_GRID_HORIZONTAL + COMMON_LVB_UNDERSCORE + COMMON_LVB_GRID_RVERTICAL }, // 6 { COMMON_LVB_GRID_HORIZONTAL + COMMON_LVB_GRID_LVERTICAL, COMMON_LVB_GRID_HORIZONTAL, COMMON_LVB_GRID_HORIZONTAL + COMMON_LVB_UNDERSCORE + COMMON_LVB_GRID_LVERTICAL, COMMON_LVB_GRID_HORIZONTAL + COMMON_LVB_UNDERSCORE + COMMON_LVB_GRID_RVERTICAL }, // 7 { COMMON_LVB_GRID_HORIZONTAL, COMMON_LVB_GRID_HORIZONTAL + COMMON_LVB_GRID_RVERTICAL, 0, COMMON_LVB_GRID_RVERTICAL }, // 8 { COMMON_LVB_GRID_HORIZONTAL + COMMON_LVB_GRID_LVERTICAL, COMMON_LVB_GRID_HORIZONTAL + COMMON_LVB_GRID_RVERTICAL, COMMON_LVB_GRID_HORIZONTAL + COMMON_LVB_UNDERSCORE + COMMON_LVB_GRID_LVERTICAL, COMMON_LVB_GRID_HORIZONTAL + COMMON_LVB_UNDERSCORE + COMMON_LVB_GRID_RVERTICAL }, // 9 { COMMON_LVB_GRID_HORIZONTAL + COMMON_LVB_GRID_LVERTICAL, COMMON_LVB_GRID_HORIZONTAL + COMMON_LVB_GRID_RVERTICAL, COMMON_LVB_GRID_HORIZONTAL + COMMON_LVB_UNDERSCORE, COMMON_LVB_GRID_HORIZONTAL + COMMON_LVB_UNDERSCORE + COMMON_LVB_GRID_RVERTICAL } };
[此贴子已经被作者于2015-10-21 19:28编辑过]