arduino의 계산기
개요
arduino에서 계산기, 시도했다.
8bit이므로 255까지
구구는 OK.
사진
샘플 코드
#define stb 10
#define clk 9
#define dio 8
uint8_t a = 0;
uint8_t b = 0;
uint8_t c = 0;
void printn(uint8_t v) {
uint8_t w = v / 100;
uint8_t x = (v - w * 100) / 10;
uint8_t y = v % 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;
if (v > 9) t = t | a[x] << 5;
if (v > 99) t = t | a[w] << 6;
shiftOut(dio, clk, LSBFIRST, t);
shiftOut(dio, clk, LSBFIRST, 0x01);
t = b[y] << 4;
if (v > 9) t = t | b[x] << 5;
if (v > 99) t = t | b[w] << 6;
shiftOut(dio, clk, LSBFIRST, t);
shiftOut(dio, clk, LSBFIRST, 0x01);
t = c[y] << 4;
if (v > 9) t = t | c[x] << 5;
if (v > 99) t = t | c[w] << 6;
shiftOut(dio, clk, LSBFIRST, t);
shiftOut(dio, clk, LSBFIRST, 0x01);
t = d[y] << 4;
if (v > 9) t = t | d[x] << 5;
if (v > 99) t = t | d[w] << 6;
shiftOut(dio, clk, LSBFIRST, t);
shiftOut(dio, clk, LSBFIRST, 0x01);
t = e[y] << 4;
if (v > 9) t = t | e[x] << 5;
if (v > 99) t = t | e[w] << 6;
shiftOut(dio, clk, LSBFIRST, t);
shiftOut(dio, clk, LSBFIRST, 0x01);
t = f[y] << 4;
if (v > 9) t = t | f[x] << 5;
if (v > 99) t = t | f[w] << 6;
shiftOut(dio, clk, LSBFIRST, t);
shiftOut(dio, clk, LSBFIRST, 0x01);
t = g[y] << 4;
if (v > 9) t = t | g[x] << 5;
if (v > 99) t = t | g[w] << 6;
shiftOut(dio, clk, LSBFIRST, t);
shiftOut(dio, clk, LSBFIRST, 0x01);
t = h[y] << 4;
if (v > 9) t = t | h[x] << 5;
if (v > 99) t = t | h[w] << 6;
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);
printn(0);
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);
if (v == 0x02)
{
btn = 3;
}
else if (v == 0x04)
{
btn = 9;
}
else if (v == 0x20)
{
btn = 12;
}
else if (v == 0x40)
{
btn = 10;
}
v = shiftIn(dio, clk, LSBFIRST);
if (v == 0x02)
{
btn = 0;
}
else if (v == 0x04)
{
btn = 4;
}
else if (v == 0x20)
{
btn = 15;
}
else if (v == 0x40)
{
btn = 5;
}
v = shiftIn(dio, clk, LSBFIRST);
if (v == 0x02)
{
btn = 14;
}
else if (v == 0x04)
{
btn = 6;
}
else if (v == 0x20)
{
btn = 13;
}
else if (v == 0x40)
{
btn = 11;
}
pinMode(dio, OUTPUT);
digitalWrite(stb, HIGH);
if (btn < 10)
{
if (b > 9)
{
c = c * 10 + btn;
printn(c);
}
else
{
a = a * 10 + btn;
printn(a);
}
}
else if (btn == 15)
{
a = 0;
b = 0;
c = 0;
printn(a);
}
else if (btn == 10)
{
b = 10;
printn(0);
}
else if (btn == 11)
{
b = 11;
printn(0);
}
else if (btn == 12)
{
b = 12;
printn(0);
}
else if (btn == 13)
{
b = 13;
printn(0);
}
else if (btn == 14)
{
if (b == 10)
{
a = a + c;
}
else if (b == 11)
{
a = a - c;
}
else if (b == 12)
{
a = a / c;
}
else if (b == 13)
{
a = a * c;
}
printn(a);
a = 0;
b = 0;
c = 0;
}
delay(300);
}
이상.
Reference
이 문제에 관하여(arduino의 계산기), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/ohisama@github/items/3b4c9351dda5805bde9d
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 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;
void printn(uint8_t v) {
uint8_t w = v / 100;
uint8_t x = (v - w * 100) / 10;
uint8_t y = v % 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;
if (v > 9) t = t | a[x] << 5;
if (v > 99) t = t | a[w] << 6;
shiftOut(dio, clk, LSBFIRST, t);
shiftOut(dio, clk, LSBFIRST, 0x01);
t = b[y] << 4;
if (v > 9) t = t | b[x] << 5;
if (v > 99) t = t | b[w] << 6;
shiftOut(dio, clk, LSBFIRST, t);
shiftOut(dio, clk, LSBFIRST, 0x01);
t = c[y] << 4;
if (v > 9) t = t | c[x] << 5;
if (v > 99) t = t | c[w] << 6;
shiftOut(dio, clk, LSBFIRST, t);
shiftOut(dio, clk, LSBFIRST, 0x01);
t = d[y] << 4;
if (v > 9) t = t | d[x] << 5;
if (v > 99) t = t | d[w] << 6;
shiftOut(dio, clk, LSBFIRST, t);
shiftOut(dio, clk, LSBFIRST, 0x01);
t = e[y] << 4;
if (v > 9) t = t | e[x] << 5;
if (v > 99) t = t | e[w] << 6;
shiftOut(dio, clk, LSBFIRST, t);
shiftOut(dio, clk, LSBFIRST, 0x01);
t = f[y] << 4;
if (v > 9) t = t | f[x] << 5;
if (v > 99) t = t | f[w] << 6;
shiftOut(dio, clk, LSBFIRST, t);
shiftOut(dio, clk, LSBFIRST, 0x01);
t = g[y] << 4;
if (v > 9) t = t | g[x] << 5;
if (v > 99) t = t | g[w] << 6;
shiftOut(dio, clk, LSBFIRST, t);
shiftOut(dio, clk, LSBFIRST, 0x01);
t = h[y] << 4;
if (v > 9) t = t | h[x] << 5;
if (v > 99) t = t | h[w] << 6;
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);
printn(0);
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);
if (v == 0x02)
{
btn = 3;
}
else if (v == 0x04)
{
btn = 9;
}
else if (v == 0x20)
{
btn = 12;
}
else if (v == 0x40)
{
btn = 10;
}
v = shiftIn(dio, clk, LSBFIRST);
if (v == 0x02)
{
btn = 0;
}
else if (v == 0x04)
{
btn = 4;
}
else if (v == 0x20)
{
btn = 15;
}
else if (v == 0x40)
{
btn = 5;
}
v = shiftIn(dio, clk, LSBFIRST);
if (v == 0x02)
{
btn = 14;
}
else if (v == 0x04)
{
btn = 6;
}
else if (v == 0x20)
{
btn = 13;
}
else if (v == 0x40)
{
btn = 11;
}
pinMode(dio, OUTPUT);
digitalWrite(stb, HIGH);
if (btn < 10)
{
if (b > 9)
{
c = c * 10 + btn;
printn(c);
}
else
{
a = a * 10 + btn;
printn(a);
}
}
else if (btn == 15)
{
a = 0;
b = 0;
c = 0;
printn(a);
}
else if (btn == 10)
{
b = 10;
printn(0);
}
else if (btn == 11)
{
b = 11;
printn(0);
}
else if (btn == 12)
{
b = 12;
printn(0);
}
else if (btn == 13)
{
b = 13;
printn(0);
}
else if (btn == 14)
{
if (b == 10)
{
a = a + c;
}
else if (b == 11)
{
a = a - c;
}
else if (b == 12)
{
a = a / c;
}
else if (b == 13)
{
a = a * c;
}
printn(a);
a = 0;
b = 0;
c = 0;
}
delay(300);
}
이상.
Reference
이 문제에 관하여(arduino의 계산기), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/ohisama@github/items/3b4c9351dda5805bde9d
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 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;
void printn(uint8_t v) {
uint8_t w = v / 100;
uint8_t x = (v - w * 100) / 10;
uint8_t y = v % 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;
if (v > 9) t = t | a[x] << 5;
if (v > 99) t = t | a[w] << 6;
shiftOut(dio, clk, LSBFIRST, t);
shiftOut(dio, clk, LSBFIRST, 0x01);
t = b[y] << 4;
if (v > 9) t = t | b[x] << 5;
if (v > 99) t = t | b[w] << 6;
shiftOut(dio, clk, LSBFIRST, t);
shiftOut(dio, clk, LSBFIRST, 0x01);
t = c[y] << 4;
if (v > 9) t = t | c[x] << 5;
if (v > 99) t = t | c[w] << 6;
shiftOut(dio, clk, LSBFIRST, t);
shiftOut(dio, clk, LSBFIRST, 0x01);
t = d[y] << 4;
if (v > 9) t = t | d[x] << 5;
if (v > 99) t = t | d[w] << 6;
shiftOut(dio, clk, LSBFIRST, t);
shiftOut(dio, clk, LSBFIRST, 0x01);
t = e[y] << 4;
if (v > 9) t = t | e[x] << 5;
if (v > 99) t = t | e[w] << 6;
shiftOut(dio, clk, LSBFIRST, t);
shiftOut(dio, clk, LSBFIRST, 0x01);
t = f[y] << 4;
if (v > 9) t = t | f[x] << 5;
if (v > 99) t = t | f[w] << 6;
shiftOut(dio, clk, LSBFIRST, t);
shiftOut(dio, clk, LSBFIRST, 0x01);
t = g[y] << 4;
if (v > 9) t = t | g[x] << 5;
if (v > 99) t = t | g[w] << 6;
shiftOut(dio, clk, LSBFIRST, t);
shiftOut(dio, clk, LSBFIRST, 0x01);
t = h[y] << 4;
if (v > 9) t = t | h[x] << 5;
if (v > 99) t = t | h[w] << 6;
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);
printn(0);
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);
if (v == 0x02)
{
btn = 3;
}
else if (v == 0x04)
{
btn = 9;
}
else if (v == 0x20)
{
btn = 12;
}
else if (v == 0x40)
{
btn = 10;
}
v = shiftIn(dio, clk, LSBFIRST);
if (v == 0x02)
{
btn = 0;
}
else if (v == 0x04)
{
btn = 4;
}
else if (v == 0x20)
{
btn = 15;
}
else if (v == 0x40)
{
btn = 5;
}
v = shiftIn(dio, clk, LSBFIRST);
if (v == 0x02)
{
btn = 14;
}
else if (v == 0x04)
{
btn = 6;
}
else if (v == 0x20)
{
btn = 13;
}
else if (v == 0x40)
{
btn = 11;
}
pinMode(dio, OUTPUT);
digitalWrite(stb, HIGH);
if (btn < 10)
{
if (b > 9)
{
c = c * 10 + btn;
printn(c);
}
else
{
a = a * 10 + btn;
printn(a);
}
}
else if (btn == 15)
{
a = 0;
b = 0;
c = 0;
printn(a);
}
else if (btn == 10)
{
b = 10;
printn(0);
}
else if (btn == 11)
{
b = 11;
printn(0);
}
else if (btn == 12)
{
b = 12;
printn(0);
}
else if (btn == 13)
{
b = 13;
printn(0);
}
else if (btn == 14)
{
if (b == 10)
{
a = a + c;
}
else if (b == 11)
{
a = a - c;
}
else if (b == 12)
{
a = a / c;
}
else if (b == 13)
{
a = a * c;
}
printn(a);
a = 0;
b = 0;
c = 0;
}
delay(300);
}
Reference
이 문제에 관하여(arduino의 계산기), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/ohisama@github/items/3b4c9351dda5805bde9d텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)