arduino의 qyf-tm1638 보드

4347 단어 Arduino

개요



arduino에서 qyf-tm1638 보드를 사용해 보았습니다.
key 주워 보았다.

사진





샘플 코드


#define stb     10
#define clk     9
#define dio     8

void printn(uint8_t v) {
    if (v > 9) return;
    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[] = {0, 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[v] << 4;
    shiftOut(dio, clk, LSBFIRST, t);
    shiftOut(dio, clk, LSBFIRST, 0x01);
    t = b[v] << 4;
    shiftOut(dio, clk, LSBFIRST, t);
    shiftOut(dio, clk, LSBFIRST, 0x01);
    t = c[v] << 4;
    shiftOut(dio, clk, LSBFIRST, t);
    shiftOut(dio, clk, LSBFIRST, 0x01);
    t = d[v] << 4;
    shiftOut(dio, clk, LSBFIRST, t);
    shiftOut(dio, clk, LSBFIRST, 0x01);
    t = e[v] << 4;
    shiftOut(dio, clk, LSBFIRST, t);
    shiftOut(dio, clk, LSBFIRST, 0x01);
    t = f[v] << 4;
    shiftOut(dio, clk, LSBFIRST, t);
    shiftOut(dio, clk, LSBFIRST, 0x01);
    t = g[v] << 4;
    shiftOut(dio, clk, LSBFIRST, t);
    shiftOut(dio, clk, LSBFIRST, 0x01);
    t = h[v] << 4;
    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);

    digitalWrite(stb, LOW);
    shiftOut(dio, clk, LSBFIRST, 0x40);
    digitalWrite(stb, HIGH);

    digitalWrite(stb, LOW);
    shiftOut(dio, clk, LSBFIRST, 0xc0);

    shiftOut(dio, clk, LSBFIRST, 0x10);
    shiftOut(dio, clk, LSBFIRST, 0x01);

    shiftOut(dio, clk, LSBFIRST, 0x10);
    shiftOut(dio, clk, LSBFIRST, 0x01);

    shiftOut(dio, clk, LSBFIRST, 0x10);
    shiftOut(dio, clk, LSBFIRST, 0x01);

    shiftOut(dio, clk, LSBFIRST, 0x10);
    shiftOut(dio, clk, LSBFIRST, 0x01);

    shiftOut(dio, clk, LSBFIRST, 0x10);
    shiftOut(dio, clk, LSBFIRST, 0x01);

    shiftOut(dio, clk, LSBFIRST, 0x10);
    shiftOut(dio, clk, LSBFIRST, 0x01);

    shiftOut(dio, clk, LSBFIRST, 0x00);
    shiftOut(dio, clk, LSBFIRST, 0x01);

    shiftOut(dio, clk, LSBFIRST, 0x00);
    shiftOut(dio, clk, LSBFIRST, 0x01);

    digitalWrite(stb, HIGH);

    digitalWrite(stb, LOW);
    shiftOut(dio, clk, LSBFIRST, 0x88);
    digitalWrite(stb, HIGH);
    Serial.print("ok");
}

void loop() {
    uint8_t v;
    uint8_t btn = 0;
    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 = 2;
    }
    else if (v == 0x20)
    {
        btn = 3;
    }
    else if (v == 0x40)
    {
        btn = 4;
    }
    v = shiftIn(dio, clk, LSBFIRST);
    if (v == 0x02)
    {
        btn = 5;
    }
    else if (v == 0x04)
    {
        btn = 6;
    }
    else if (v == 0x20)
    {
        btn = 7;
    }
    else if (v == 0x40)
    {
        btn = 8;
    }
    v = shiftIn(dio, clk, LSBFIRST);
    if (v == 0x02)
    {
        btn = 9;
    }
    else if (v == 0x04)
    {
        btn = 10;
    }
    else if (v == 0x20)
    {
        btn = 11;
    }
    else if (v == 0x40)
    {
        btn = 12;
    }
    v = shiftIn(dio, clk, LSBFIRST);
    if (v == 0x02)
    {
        btn = 13;
    }
    else if (v == 0x04)
    {
        btn = 14;
    }
    else if (v == 0x20)
    {
        btn = 15;
    }
    else if (v == 0x40)
    {
        btn = 16;
    }
    pinMode(dio, OUTPUT);
    digitalWrite(stb, HIGH);
    if (btn > 0) 
    {
      printn(btn);
      Serial.println(btn);
    }
    delay(500);
}






이상.

좋은 웹페이지 즐겨찾기