티스토리 뷰

unsigned int displayNum = 0;
byte fndData[10][7] = {
  {0, 0, 0, 0, 0, 0, 1},  //0
  {1, 0, 0, 1, 1, 1, 1},  //1
  {0, 0, 1, 0, 0, 1, 0},  //2
  {0, 0, 0, 0, 1, 1, 0},  //3
  {1, 0, 0, 1, 1, 0, 0},  //4
  {0, 1, 0, 0, 1, 0, 0},  //5
  {0, 1, 0, 0, 0, 0, 0},  //6
  {0, 0, 0, 1, 1, 1, 1},  //7
  {0, 0, 0, 0, 0, 0, 0},  //8
  {0, 0, 0, 0, 1, 0, 0},  //9
};

void setup()  {
  for(int i = 6 ; i < 14 ; i++)  {
    pinMode(i, OUTPUT);
    digitalWrite(i, HIGH);
  }
}

void loop()  {
  setFndNum(displayNum++);
  if(displayNum > 9)  displayNum = 0;
  delay(1000);
}

void setFndNum(int num)  {
  for(int i = 6 ; i < 13 ; i++)  {
    digitalWrite(i, fndData[num][i - 6]);
  }
}

// FND + 스위치를 이용한 주사위
boolean isBreak = false;
byte fndData[6][7] = {
  {1, 0, 0, 1, 1, 1, 1},  //1
  {0, 0, 1, 0, 0, 1, 0},  //2
  {0, 0, 0, 0, 1, 1, 0},  //3
  {1, 0, 0, 1, 1, 0, 0},  //4
  {0, 1, 0, 0, 1, 0, 0},  //5
  {0, 1, 0, 0, 0, 0, 0},  //6
};

void setup()  {
  for(int i = 6 ; i < 14 ; i++)  {
    pinMode(i, OUTPUT);
    digitalWrite(i, HIGH);
  }
  pinMode(2, INPUT_PULLUP);
  attachInterrupt(0, interrupt, FALLING);
}

void loop()  {
  if(!isBreak)  {
    setFndNum(random(1, 7));
    delay(50);
  }
}

void setFndNum(int num)  {
  for(int i = 6 ; i < 13 ; i++)  {
    digitalWrite(i, fndData[num - 1][i - 6]);
  }
}

void interrupt()  {
  isBreak = !isBreak;
}
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
TAG
more
«   2025/01   »
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
글 보관함