arduino에서 시계
개요
시계(lumi time)가 망가졌으므로, arduino로 만들어 보자.
사진
샘플 코드
#define stb 10
#define clk 9
#define dio 8
uint8_t a = 0;
uint8_t b = 0;
uint8_t c = 0;
uint8_t dhor = 12;
uint8_t dmin = 34;
uint8_t dsec = 00;
int tOffset;
boolean latch = false;
void up() {
uint8_t u = dhor / 10;
uint8_t w = dhor % 10;
uint8_t x = dmin / 10;
uint8_t y = dmin % 10;
uint8_t t;
uint8_t a[] = {1, 0, 1, 1, 0, 1, 0, 1, 1, 1};
uint8_t b[] = {1, 1, 1, 1, 1, 0, 0, 1, 1, 1};
uint8_t c[] = {1, 1, 0, 1, 1, 1, 1, 1, 1, 1};
uint8_t d[] = {1, 0, 1, 1, 0, 1, 1, 0, 1, 0};
uint8_t e[] = {1, 0, 1, 0, 0, 0, 1, 0, 1, 0};
uint8_t f[] = {1, 0, 0, 0, 1, 1, 1, 0, 1, 1};
uint8_t g[] = {0, 0, 1, 1, 1, 1, 1, 0, 1, 1};
uint8_t h[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
digitalWrite(stb, LOW);
shiftOut(dio, clk, LSBFIRST, 0x40);
digitalWrite(stb, HIGH);
digitalWrite(stb, LOW);
shiftOut(dio, clk, LSBFIRST, 0xc0);
t = a[y] << 4;
t = t | a[x] << 5;
t = t | a[w] << 6;
t = t | a[u] << 7;
shiftOut(dio, clk, LSBFIRST, t);
shiftOut(dio, clk, LSBFIRST, 0x01);
t = b[y] << 4;
t = t | b[x] << 5;
t = t | b[w] << 6;
t = t | b[u] << 7;
shiftOut(dio, clk, LSBFIRST, t);
shiftOut(dio, clk, LSBFIRST, 0x01);
t = c[y] << 4;
t = t | c[x] << 5;
t = t | c[w] << 6;
t = t | c[u] << 7;
shiftOut(dio, clk, LSBFIRST, t);
shiftOut(dio, clk, LSBFIRST, 0x01);
t = d[y] << 4;
t = t | d[x] << 5;
t = t | d[w] << 6;
t = t | d[u] << 7;
shiftOut(dio, clk, LSBFIRST, t);
shiftOut(dio, clk, LSBFIRST, 0x01);
t = e[y] << 4;
t = t | e[x] << 5;
t = t | e[w] << 6;
t = t | e[u] << 7;
shiftOut(dio, clk, LSBFIRST, t);
shiftOut(dio, clk, LSBFIRST, 0x01);
t = f[y] << 4;
t = t | f[x] << 5;
t = t | f[w] << 6;
t = t | f[u] << 7;
shiftOut(dio, clk, LSBFIRST, t);
shiftOut(dio, clk, LSBFIRST, 0x01);
t = g[y] << 4;
t = t | g[x] << 5;
t = t | g[w] << 6;
t = t | g[u] << 7;
shiftOut(dio, clk, LSBFIRST, t);
shiftOut(dio, clk, LSBFIRST, 0x01);
t = h[y] << 4;
t = t | h[x] << 5;
t = t | h[w] << 6;
t = t | h[u] << 7;
shiftOut(dio, clk, LSBFIRST, t);
shiftOut(dio, clk, LSBFIRST, 0x01);
digitalWrite(stb, HIGH);
}
void setup() {
Serial.begin(9600);
pinMode(stb, OUTPUT);
pinMode(clk, OUTPUT);
pinMode(dio, OUTPUT);
digitalWrite(stb, LOW);
shiftOut(dio, clk, LSBFIRST, 0x88);
digitalWrite(stb, HIGH);
tOffset = 500 - millis() % 1000;
Serial.print("ok");
}
void loop() {
uint8_t v;
uint8_t btn = 20;
digitalWrite(stb, LOW);
shiftOut(dio, clk, LSBFIRST, 0x42);
pinMode(dio, INPUT);
v = shiftIn(dio, clk, LSBFIRST);
if (v == 0x02)
{
btn = 1;
}
else if (v == 0x04)
{
btn = 7;
}
else if (v == 0x20)
{
btn = 2;
}
else if (v == 0x40)
{
btn = 8;
}
v = shiftIn(dio, clk, LSBFIRST);
v = shiftIn(dio, clk, LSBFIRST);
v = shiftIn(dio, clk, LSBFIRST);
pinMode(dio, OUTPUT);
digitalWrite(stb, HIGH);
if (btn == 1)
{
dmin--;
}
if (btn == 2)
{
dhor--;
}
if (btn == 7)
{
dmin++;
}
if (btn == 8)
{
dhor++;
}
if ((millis() - tOffset) % 1000 < 500)
{
latch = true;
}
if (((millis() - tOffset) % 1000 >= 500) && latch)
{
latch = false;
dsec++;
if (dsec == 60)
{
dsec = 0;
dmin++;
if (dmin == 60)
{
dmin = 0;
dhor++;
if (dhor == 24)
{
dhor = 0;
}
}
}
}
up();
delay(300);
}
이상.
Reference
이 문제에 관하여(arduino에서 시계), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/ohisama@github/items/5e57592fdca7e25af40d
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
샘플 코드
#define stb 10
#define clk 9
#define dio 8
uint8_t a = 0;
uint8_t b = 0;
uint8_t c = 0;
uint8_t dhor = 12;
uint8_t dmin = 34;
uint8_t dsec = 00;
int tOffset;
boolean latch = false;
void up() {
uint8_t u = dhor / 10;
uint8_t w = dhor % 10;
uint8_t x = dmin / 10;
uint8_t y = dmin % 10;
uint8_t t;
uint8_t a[] = {1, 0, 1, 1, 0, 1, 0, 1, 1, 1};
uint8_t b[] = {1, 1, 1, 1, 1, 0, 0, 1, 1, 1};
uint8_t c[] = {1, 1, 0, 1, 1, 1, 1, 1, 1, 1};
uint8_t d[] = {1, 0, 1, 1, 0, 1, 1, 0, 1, 0};
uint8_t e[] = {1, 0, 1, 0, 0, 0, 1, 0, 1, 0};
uint8_t f[] = {1, 0, 0, 0, 1, 1, 1, 0, 1, 1};
uint8_t g[] = {0, 0, 1, 1, 1, 1, 1, 0, 1, 1};
uint8_t h[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
digitalWrite(stb, LOW);
shiftOut(dio, clk, LSBFIRST, 0x40);
digitalWrite(stb, HIGH);
digitalWrite(stb, LOW);
shiftOut(dio, clk, LSBFIRST, 0xc0);
t = a[y] << 4;
t = t | a[x] << 5;
t = t | a[w] << 6;
t = t | a[u] << 7;
shiftOut(dio, clk, LSBFIRST, t);
shiftOut(dio, clk, LSBFIRST, 0x01);
t = b[y] << 4;
t = t | b[x] << 5;
t = t | b[w] << 6;
t = t | b[u] << 7;
shiftOut(dio, clk, LSBFIRST, t);
shiftOut(dio, clk, LSBFIRST, 0x01);
t = c[y] << 4;
t = t | c[x] << 5;
t = t | c[w] << 6;
t = t | c[u] << 7;
shiftOut(dio, clk, LSBFIRST, t);
shiftOut(dio, clk, LSBFIRST, 0x01);
t = d[y] << 4;
t = t | d[x] << 5;
t = t | d[w] << 6;
t = t | d[u] << 7;
shiftOut(dio, clk, LSBFIRST, t);
shiftOut(dio, clk, LSBFIRST, 0x01);
t = e[y] << 4;
t = t | e[x] << 5;
t = t | e[w] << 6;
t = t | e[u] << 7;
shiftOut(dio, clk, LSBFIRST, t);
shiftOut(dio, clk, LSBFIRST, 0x01);
t = f[y] << 4;
t = t | f[x] << 5;
t = t | f[w] << 6;
t = t | f[u] << 7;
shiftOut(dio, clk, LSBFIRST, t);
shiftOut(dio, clk, LSBFIRST, 0x01);
t = g[y] << 4;
t = t | g[x] << 5;
t = t | g[w] << 6;
t = t | g[u] << 7;
shiftOut(dio, clk, LSBFIRST, t);
shiftOut(dio, clk, LSBFIRST, 0x01);
t = h[y] << 4;
t = t | h[x] << 5;
t = t | h[w] << 6;
t = t | h[u] << 7;
shiftOut(dio, clk, LSBFIRST, t);
shiftOut(dio, clk, LSBFIRST, 0x01);
digitalWrite(stb, HIGH);
}
void setup() {
Serial.begin(9600);
pinMode(stb, OUTPUT);
pinMode(clk, OUTPUT);
pinMode(dio, OUTPUT);
digitalWrite(stb, LOW);
shiftOut(dio, clk, LSBFIRST, 0x88);
digitalWrite(stb, HIGH);
tOffset = 500 - millis() % 1000;
Serial.print("ok");
}
void loop() {
uint8_t v;
uint8_t btn = 20;
digitalWrite(stb, LOW);
shiftOut(dio, clk, LSBFIRST, 0x42);
pinMode(dio, INPUT);
v = shiftIn(dio, clk, LSBFIRST);
if (v == 0x02)
{
btn = 1;
}
else if (v == 0x04)
{
btn = 7;
}
else if (v == 0x20)
{
btn = 2;
}
else if (v == 0x40)
{
btn = 8;
}
v = shiftIn(dio, clk, LSBFIRST);
v = shiftIn(dio, clk, LSBFIRST);
v = shiftIn(dio, clk, LSBFIRST);
pinMode(dio, OUTPUT);
digitalWrite(stb, HIGH);
if (btn == 1)
{
dmin--;
}
if (btn == 2)
{
dhor--;
}
if (btn == 7)
{
dmin++;
}
if (btn == 8)
{
dhor++;
}
if ((millis() - tOffset) % 1000 < 500)
{
latch = true;
}
if (((millis() - tOffset) % 1000 >= 500) && latch)
{
latch = false;
dsec++;
if (dsec == 60)
{
dsec = 0;
dmin++;
if (dmin == 60)
{
dmin = 0;
dhor++;
if (dhor == 24)
{
dhor = 0;
}
}
}
}
up();
delay(300);
}
이상.
Reference
이 문제에 관하여(arduino에서 시계), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/ohisama@github/items/5e57592fdca7e25af40d
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
#define stb 10
#define clk 9
#define dio 8
uint8_t a = 0;
uint8_t b = 0;
uint8_t c = 0;
uint8_t dhor = 12;
uint8_t dmin = 34;
uint8_t dsec = 00;
int tOffset;
boolean latch = false;
void up() {
uint8_t u = dhor / 10;
uint8_t w = dhor % 10;
uint8_t x = dmin / 10;
uint8_t y = dmin % 10;
uint8_t t;
uint8_t a[] = {1, 0, 1, 1, 0, 1, 0, 1, 1, 1};
uint8_t b[] = {1, 1, 1, 1, 1, 0, 0, 1, 1, 1};
uint8_t c[] = {1, 1, 0, 1, 1, 1, 1, 1, 1, 1};
uint8_t d[] = {1, 0, 1, 1, 0, 1, 1, 0, 1, 0};
uint8_t e[] = {1, 0, 1, 0, 0, 0, 1, 0, 1, 0};
uint8_t f[] = {1, 0, 0, 0, 1, 1, 1, 0, 1, 1};
uint8_t g[] = {0, 0, 1, 1, 1, 1, 1, 0, 1, 1};
uint8_t h[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
digitalWrite(stb, LOW);
shiftOut(dio, clk, LSBFIRST, 0x40);
digitalWrite(stb, HIGH);
digitalWrite(stb, LOW);
shiftOut(dio, clk, LSBFIRST, 0xc0);
t = a[y] << 4;
t = t | a[x] << 5;
t = t | a[w] << 6;
t = t | a[u] << 7;
shiftOut(dio, clk, LSBFIRST, t);
shiftOut(dio, clk, LSBFIRST, 0x01);
t = b[y] << 4;
t = t | b[x] << 5;
t = t | b[w] << 6;
t = t | b[u] << 7;
shiftOut(dio, clk, LSBFIRST, t);
shiftOut(dio, clk, LSBFIRST, 0x01);
t = c[y] << 4;
t = t | c[x] << 5;
t = t | c[w] << 6;
t = t | c[u] << 7;
shiftOut(dio, clk, LSBFIRST, t);
shiftOut(dio, clk, LSBFIRST, 0x01);
t = d[y] << 4;
t = t | d[x] << 5;
t = t | d[w] << 6;
t = t | d[u] << 7;
shiftOut(dio, clk, LSBFIRST, t);
shiftOut(dio, clk, LSBFIRST, 0x01);
t = e[y] << 4;
t = t | e[x] << 5;
t = t | e[w] << 6;
t = t | e[u] << 7;
shiftOut(dio, clk, LSBFIRST, t);
shiftOut(dio, clk, LSBFIRST, 0x01);
t = f[y] << 4;
t = t | f[x] << 5;
t = t | f[w] << 6;
t = t | f[u] << 7;
shiftOut(dio, clk, LSBFIRST, t);
shiftOut(dio, clk, LSBFIRST, 0x01);
t = g[y] << 4;
t = t | g[x] << 5;
t = t | g[w] << 6;
t = t | g[u] << 7;
shiftOut(dio, clk, LSBFIRST, t);
shiftOut(dio, clk, LSBFIRST, 0x01);
t = h[y] << 4;
t = t | h[x] << 5;
t = t | h[w] << 6;
t = t | h[u] << 7;
shiftOut(dio, clk, LSBFIRST, t);
shiftOut(dio, clk, LSBFIRST, 0x01);
digitalWrite(stb, HIGH);
}
void setup() {
Serial.begin(9600);
pinMode(stb, OUTPUT);
pinMode(clk, OUTPUT);
pinMode(dio, OUTPUT);
digitalWrite(stb, LOW);
shiftOut(dio, clk, LSBFIRST, 0x88);
digitalWrite(stb, HIGH);
tOffset = 500 - millis() % 1000;
Serial.print("ok");
}
void loop() {
uint8_t v;
uint8_t btn = 20;
digitalWrite(stb, LOW);
shiftOut(dio, clk, LSBFIRST, 0x42);
pinMode(dio, INPUT);
v = shiftIn(dio, clk, LSBFIRST);
if (v == 0x02)
{
btn = 1;
}
else if (v == 0x04)
{
btn = 7;
}
else if (v == 0x20)
{
btn = 2;
}
else if (v == 0x40)
{
btn = 8;
}
v = shiftIn(dio, clk, LSBFIRST);
v = shiftIn(dio, clk, LSBFIRST);
v = shiftIn(dio, clk, LSBFIRST);
pinMode(dio, OUTPUT);
digitalWrite(stb, HIGH);
if (btn == 1)
{
dmin--;
}
if (btn == 2)
{
dhor--;
}
if (btn == 7)
{
dmin++;
}
if (btn == 8)
{
dhor++;
}
if ((millis() - tOffset) % 1000 < 500)
{
latch = true;
}
if (((millis() - tOffset) % 1000 >= 500) && latch)
{
latch = false;
dsec++;
if (dsec == 60)
{
dsec = 0;
dmin++;
if (dmin == 60)
{
dmin = 0;
dhor++;
if (dhor == 24)
{
dhor = 0;
}
}
}
}
up();
delay(300);
}
Reference
이 문제에 관하여(arduino에서 시계), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/ohisama@github/items/5e57592fdca7e25af40d텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)