1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
|
// LCD Clock.cpp : Defines the entry point for the console application.
#include <stdafx.h> // For Microsoft Express. Delete if using different one.
#include <ctime>
#include <conio.h>
#include <iostream>
#include <string>
#include <windows.h>
using namespace std;
HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE);
COORD CursorPosition;
void Draw(int style, int col, int row, int length,int amount, bool fill, int sw );
void gotoXY(int x, int y );
void gotoXY(int x, int y, string text);
void setcursor(bool visible, DWORD size);
int main()
{
setcursor(0,0);
int hours, minutes, seconds, t;
struct tm * timeinfo;
bool Military_Time = false;
string AM_PM;
string Segment[11][10]={
{" \x11\xDB\xDB\xDB\x10 "," "," \x11\xDB\xDB\xDB\x10 "," \x11\xDB\xDB\xDB\x10 "," "," \x11\xDB\xDB\xDB\x10 "," \x11\xDB\xDB\xDB\x10 "," \x11\xDB\xDB\xDB\x10 "," \x11\xDB\xDB\xDB\x10 "," \x11\xDB\xDB\xDB\x10 "},
{"\x1E \x1E"," \x1E"," \x1E"," \x1E","\x1E \x1E","\x1E ","\x1E "," \x1E","\x1E \x1E","\x1E \x1E"},
{"\xDB \xDB"," \xDB"," \xDB"," \xDB","\xDB \xDB","\xDB ","\xDB "," \xDB","\xDB \xDB","\xDB \xDB"},
{"\xDB \xDB"," \xDB"," \xDB"," \xDB","\xDB \xDB","\xDB ","\xDB "," \xDB","\xDB \xDB","\xDB \xDB"},
{"\x1F \x1F"," \x1F"," \x1F"," \x1F","\x1F \x1F","\x1F ","\x1F "," \x1F","\x1F \x1F","\x1F \x1F"},
{" "," ", " \x11\xDB\xDB\xDB\x10 "," \x11\xDB\xDB\xDB\x10 "," \x11\xDB\xDB\xDB\x10 "," \x11\xDB\xDB\xDB\x10 "," \x11\xDB\xDB\xDB\x10 "," "," \x11\xDB\xDB\xDB\x10 "," \x11\xDB\xDB\xDB\x10 "},
{"\x1E \x1E"," \x1E","\x1E "," \x1E"," \x1E"," \x1E","\x1E \x1E"," \x1E","\x1E \x1E"," \x1E"},
{"\xDB \xDB"," \xDB","\xDB "," \xDB"," \xDB"," \xDB","\xDB \xDB"," \xDB","\xDB \xDB"," \xDB"},
{"\xDB \xDB"," \xDB","\xDB "," \xDB"," \xDB"," \xDB","\xDB \xDB"," \xDB","\xDB \xDB"," \xDB"},
{"\x1F \x1F"," \x1F","\x1F "," \x1F"," \x1F"," \x1F","\x1F \x1F"," \x1F","\x1F \x1F"," \x1F"},
{" \x11\xDB\xDB\xDB\x10 "," "," \x11\xDB\xDB\xDB\x10 "," \x11\xDB\xDB\xDB\x10 "," "," \x11\xDB\xDB\xDB\x10 "," \x11\xDB\xDB\xDB\x10 "," "," \x11\xDB\xDB\xDB\x10 "," \x11\xDB\xDB\xDB\x10 "}
};
string Colon[11][1] = {
{" "},
{" "},
{" "},
{" \xFE "},
{" "},
{" "},
{" "},
{" \xFE "},
{" "},
{" "},
{" "}
};
Draw(2,2,5,76,15,0,2);
gotoXY(26,12,"Pressing the \"M\" key");
gotoXY(26,14,"toggles Military Time");
Sleep(2000);
Draw(1,4,6,72,13,1,0);
gotoXY(73,8,"HR");
do
{
time_t rawtime;
time ( &rawtime );
timeinfo = localtime( &rawtime );
hours = timeinfo->tm_hour;
seconds = timeinfo->tm_sec;
minutes = timeinfo->tm_min;
if (_kbhit())
{
char ch = _getch();
ch = toupper(ch);
if (ch == 'M')
{
Military_Time = !Military_Time;
ch = ' ';
}
}
if( Military_Time)
{
AM_PM = " ";
gotoXY(73,7,"24");
}
else
{
AM_PM = "AM";
gotoXY(73,7,"12");
if ( hours >= 12)
AM_PM = "PM";
if ( hours == 0 )
hours = 12;
if ( hours > 12)
hours -=12;
}
for(t=0;t<11;t++)
{
gotoXY(6,7+t);
cout << Segment[t][hours/10] << " " << Segment[t][hours%10] << Colon[t][0] << Segment[t][minutes/10] << " " << Segment[t][minutes%10] << Colon[t][0] << Segment[t][seconds/10] << " " << Segment[t][seconds%10];
}
gotoXY(73,17, AM_PM);
Sleep(1000);
} while (true);
}
void Draw(int style, int col, int row, int length,int amount, bool fill, int sw )
{
// Draws a 1 or 2 line box
int a;
if ( sw >4)
sw = 4;
style=(style-1)*6;
char box[24];
char shdw[5];
box[0] = '\xDA';// ┌ Draw(1,...);
box[1] = '\xBF';// ┐
box[2] = '\xC0';// └
box[3] = '\xD9';// ┘
box[4] = '\xB3';// │
box[5] = '\xC4';// ─
box[6] = '\xC9';// ╔ Draw(2,...);
box[7] = '\xBB';// ╗
box[8] = '\xC8';// ╚
box[9] = '\xBC';// ╝
box[10] = '\xBA';// ║
box[11] = '\xCD';// ═
box[12] = '\xD5';// ╒ Draw(3,...);
box[13] = '\xB8';// ╕
box[14] = '\xD4';// ╘
box[15] = '\xBE';// ╛
box[16] = '\xB3';// │
box[17] = '\xCD';// ═
box[18] = '\xD6';// ╓ Draw(4,...);
box[19] = '\xB7';// ╖
box[20] = '\xD3';// ╙
box[21] = '\xBD';// ╜
box[22] = '\xBA';// ║
box[23] = '\xC4';// ─
shdw[1] = '\xB0';// ░
shdw[2] = '\xB1';// ▒
shdw[3] = '\xB2';// ▓
shdw[4] = '\xDB';// █
char tl,tr,bl,br,side,edge,shadow;
tl = box[style];
tr = box[style+1];
bl = box[style+2];
br = box[style+3];
side = box[style+4];
edge = box[style+5];
shadow = shdw[sw];
string Line(length-2,edge);
string Shadow(length,shadow);
string Fill(length-2, ' ');
gotoXY(col,row);
cout << tl << Line << tr;
for (a = 1; a <amount-1;a++)
{
gotoXY(col,row+a);
cout << side;
if (fill)
cout << Fill;
else
gotoXY(col+length-1,row+a);
cout << side;
if (sw)
cout << shadow;
}
gotoXY(col,(amount+row)-1);
cout << bl << Line << br;
if (sw)
{
cout << shadow;
gotoXY(col+1,row+amount , Shadow );
}
}
void gotoXY(int x, int y)
{
CursorPosition.X = x;
CursorPosition.Y = y;
SetConsoleCursorPosition(console,CursorPosition);
}
void gotoXY(int x, int y, string text)
{
CursorPosition.X = x;
CursorPosition.Y = y;
SetConsoleCursorPosition(console,CursorPosition);
cout << text;
}
void setcursor(bool visible, DWORD size) // set bool visible = 0 - invisible, bool visible = 1 - visible
{
if(size == 0)
{
size = 20; // default cursor size
}
CONSOLE_CURSOR_INFO lpCursor;
lpCursor.bVisible = visible;
lpCursor.dwSize = size;
SetConsoleCursorInfo(console,&lpCursor);
}
|