LED-7 Segments 3 Column กับ Arduino
Arduino Programming
ผู้เขียน: Prajin Palangsantikul (www.appsofttech.com)
/*
/ Program: EX_0314.ino
/ Purpose: LED-7 Segments 3 Column
*/
#define LOOP_PLAY 150
const char pin_seg[] = { 2, 3, 4, // digit 1,2,3
5, 6, 7, 8, // a, b, c, d
9, 10, 11, 12, // e, f, g, dp
};
const char led_num[] = { 0x3F, 0x06, 0x5B, 0x4F, 0x66, //0,1,2,3,4
0x6D, 0x7D, 0x07, 0x7F, 0x6F, //5,6,7,8,9
0x77, 0x7C, 0x39, 0x5E, 0x79, //A,b,C,d,E
0x71, 0x80, //F,.
};
int iNum = 0;
int iPin = 0;
// Initialize variables, pin modes & libraries
void setup()
{
iPin = sizeof(pin_seg); // Check array size
for(int i=0; i {
pinMode(pin_seg[i], OUTPUT);
}
}
// Main loop
void loop()
{
for(int i=0; i {
DisplayNum(pin_seg[0], ((iNum%100)%10));
DisplayNum(pin_seg[1], ((iNum%100)/10));
DisplayNum(pin_seg[2], (iNum/100));
}
if (iNum++ > 999) iNum = 0; // Count number
}
// Display Number LED-7 Segments
void DisplayNum(int digit, int num)
{
char digital = led_num[num];
// Select digit (On/Off Digit LED 7 Segments)
if (digit != pin_seg[0]) digitalWrite(pin_seg[0], HIGH);
if (digit != pin_seg[1]) digitalWrite(pin_seg[1], HIGH);
if (digit != pin_seg[2]) digitalWrite(pin_seg[2], HIGH);
digitalWrite(digit, LOW);
// Output Segments
for(int i=3; i {
if (digital & 0x01)
digitalWrite(pin_seg[i], HIGH);
else
digitalWrite(pin_seg[i], LOW);
digital = digital >> 1;
}
delay(1);
}
ผู้เขียน: Prajin Palangsantikul (www.appsofttech.com)
/*
/ Program: EX_0314.ino
/ Purpose: LED-7 Segments 3 Column
*/
#define LOOP_PLAY 150
const char pin_seg[] = { 2, 3, 4, // digit 1,2,3
5, 6, 7, 8, // a, b, c, d
9, 10, 11, 12, // e, f, g, dp
};
const char led_num[] = { 0x3F, 0x06, 0x5B, 0x4F, 0x66, //0,1,2,3,4
0x6D, 0x7D, 0x07, 0x7F, 0x6F, //5,6,7,8,9
0x77, 0x7C, 0x39, 0x5E, 0x79, //A,b,C,d,E
0x71, 0x80, //F,.
};
int iNum = 0;
int iPin = 0;
// Initialize variables, pin modes & libraries
void setup()
{
iPin = sizeof(pin_seg); // Check array size
for(int i=0; i
pinMode(pin_seg[i], OUTPUT);
}
}
// Main loop
void loop()
{
for(int i=0; i
DisplayNum(pin_seg[0], ((iNum%100)%10));
DisplayNum(pin_seg[1], ((iNum%100)/10));
DisplayNum(pin_seg[2], (iNum/100));
}
if (iNum++ > 999) iNum = 0; // Count number
}
// Display Number LED-7 Segments
void DisplayNum(int digit, int num)
{
char digital = led_num[num];
// Select digit (On/Off Digit LED 7 Segments)
if (digit != pin_seg[0]) digitalWrite(pin_seg[0], HIGH);
if (digit != pin_seg[1]) digitalWrite(pin_seg[1], HIGH);
if (digit != pin_seg[2]) digitalWrite(pin_seg[2], HIGH);
digitalWrite(digit, LOW);
// Output Segments
for(int i=3; i
if (digital & 0x01)
digitalWrite(pin_seg[i], HIGH);
else
digitalWrite(pin_seg[i], LOW);
digital = digital >> 1;
}
delay(1);
}
ความคิดเห็น
แสดงความคิดเห็น