// 七段顯示器製作倒數功能 (v2)
#define DARK 0
#define LIGHT 1
// abcdefgp
int S7table[] = {0xFC,0x60,0xDA,0xF2,0x66,0xB6,
0xBE,0xE0,0xFE,0xF6,0xEE,0x3E,0x9C,0x7A,0x9E,0x8E};
// a b c d e f g p
//char S7pin[] = {2,3,5,7,8,10,9,4}; //(X)
// p g f e d c b a
unsigned char S7pin[] = {4,9,10,8,7,5,3,2};
void setup() {
for ( int i=0; i<=7; i++ ) pinMode(S7pin[i], OUTPUT);
}
// 在七段顯示器上顯示指定的一個數字 n
void disp7S(int n) {
for ( int i=0; i<=7; i++ ) {
char pin = S7pin[i];
char val = 1<
digitalWrite( pin , val );
//digitalWrite( S7pin[i] , 1<
}
}
void loop() {
static int num = 0;
disp7S( num );
if ( ++num >= 10 ) num = 0;
delay(300); // 暫停 0.5 秒鐘
}
#include <_stdio.h_>
#include <_stdlib.h_>
#include <_time.h_>
#define MAX 52
#define MIN 1
int card[MAX+1] = {0};
void get_card( int *addr ) ; //宣告
int main() {
get_card( &card[0] ); // card = &card[0] = card[0] 的位址
for( int i = MIN;i <= MAX; i++ ) {
printf("-,",card[i]);
if(i % 10 == 0)printf("\n");//10張就斷行
}
return 0;
}
void get_card( int *addr ) { //*=位址變數
int done[MAX+1] = {0}, busy = 1;
int i = 0;//發到第幾張牌
//for( int i = 1;i<=52;i++ ) printf("- ",done[i]);
srand( clock() );//洗牌
while( 1 ) {
if(++i > MAX ) break;
busy = 1;
while( busy ) {
int n = rand() % MAX + MIN; //(0~51)+1=1~52
if( done[n] == 0 ) {
done[n] = 1;//表示發出去的牌
card[i] = n;//發出去的這張牌
busy = 0;
}
}
}
}