//*******************************************************************************
//------------------------- ตัวอย่าง การใช้งาน 7 segment ---------------------------
//----------------ตัวอย่างโปรแกรมใช้กับ:Arduino UNO R3------------------------------
//----------------ชมสินค้าเพิ่มเติมได้ที:http://www.arduinothai.com -------------------
//*******************************************************************************/
int latchPin = 4;
int clockPin =7;
int dataPin = 8;
int count =0;
int times =0;
int times2 =0;
unsigned char Dis_table[] = {0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0X80,0X90}; // ค่าตัวเลขที่ใช้แสดงใน 7 segment
unsigned char Dis_buf[] = {0xF1,0xF2,0xF4,0xF8}; //ตำแหน่งของ 7 segment ที่ต้องการแสดง
void setup ()
{
pinMode(latchPin,OUTPUT); // กำหนดให้ pin ที่ต้องการใช้งาน ทำงานเป็น OUTPUT
pinMode(clockPin,OUTPUT);
pinMode(dataPin,OUTPUT);
}
void loop()
{
for(int i =0; i <=3; i++) // แสดงตัวเลขที่ 7 segment
{
digitalWrite(latchPin,LOW); // เคลียร์ค่าตัวเลข
shiftOut(dataPin,clockPin,MSBFIRST,Dis_table[count]); // ตัวเลขที่จะแสดง
shiftOut(dataPin,clockPin,MSBFIRST,Dis_buf[i] ); // ตำแหน่งที่จะแสดง
digitalWrite(latchPin,HIGH); // แสดงค่าตัวเลข
delay(2);
}
times2 = millis();
if((times2 - times) >= 1000)
{
count++;
if(count > 9)
count = 0;
times = millis();
}
}