배송 |
---|
상품 정보 | 가격 | 삭제 |
---|---|---|
[7 세그먼트 모듈 4칸 Grove Type] 아두이노 | ||
TOTAL PRICE(수량) 0 |
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 | #include <Arduino.h> #include <TM1637Display.h> #define CLK 9 #define DIO 8 TM1637Display display(CLK, DIO); // TM1637 디스플레이 객체 생성 int Sec1, Sec2, Min1, Min2, Tm1, Tm2 = 0; // 시간 변수 선언 unsigned long previousTime, currentTime; // 이전 및 현재 시간 변수 선언 uint8_t data[] = {0x0, 0x0, 0x0, 0x0}; // 디스플레이에 표시할 데이터 배열 uint8_t segto; // 디스플레이에 표시할 세그먼트 값 void setup() { previousTime = millis(); // 이전 시간 초기화 display.setBrightness(0xF); // 디스플레이 밝기 설정 Serial.begin(9600); // 시리얼 통신 시작 } void loop() { currentTime = millis() / 1000; // 현재 시간 계산 (초 단위) // 각 자릿수를 계산 Sec2 = currentTime % 10; Sec1 = (currentTime / 10) % 10; Min2 = (currentTime / 100) % 10; Min1 = (currentTime / 1000) % 10; // 디스플레이에 표시할 데이터 배열 설정 data[0] = display.encodeDigit(Min1); data[1] = display.encodeDigit(Min2); data[2] = display.encodeDigit(Sec1); data[3] = display.encodeDigit(Sec2); // 두 번째 자릿수의 세그먼트 설정 segto = 0x80 | display.encodeDigit(Min2); // 디스플레이에 데이터 및 두 번째 자릿수의 세그먼트 표시 display.setSegments(data); display.setSegments(&segto, 1, 1); delay(500); // 500ms 지연 // 디스플레이 초기화 및 500ms 지연 display.setSegments(data); delay(500); } | cs |