https://www.youtube.com/watch?v=PN43HDvVZh8
โค้ดส่งฟรี Shopee https://shope.ee/6ze2MNCRiS
PJ#2 รูเล็ต 10ดวง Roulette 10 LED
4/4/2565 SONGCHAI PRAPATRUNGSEE
* 31/3/2022
*/
int num[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80,0x01,0x02};
int i,ib,j,time_n=30,x,PDL,PBL,z,swL,swT,blinkT,blinkL,blinkF;
int numL;
void beep();
void setup() {
// initialize Timer1
cli(); // disable global interrupts
TCCR1A = 0; // TCCR1A register = 0
TCCR1B = 0; // TCCR1A register = 0
TIMSK1 |= (1 << TOIE1);// enable Timer1 overflow interrupt:
TCNT1=64286;// Preload 20mS
TCCR1B |= (1 << CS12); // Sets bit CS12 in TCCR1B
sei();// enable global interrupts:
// initialize digital pin .
DDRD = 0xFF; // 0-7 OUTPUT
DDRB = 0xFF;
DDRC = 0xFF;
pinMode(A2, INPUT_PULLUP);
pinMode(A3, OUTPUT);
}
ISR(TIMER1_OVF_vect){
TCNT1=64286;// reload 20mS
if(digitalRead(A2)==0&&swL==0){
if(swT++>=2){
swL=1;
swT=0;
blinkF=1;
numL=1;
}
}else if(digitalRead(A2)==1){
swL=0;
swT=0;
}
if(blinkF==0){
blinkT++;
if(blinkT==25&&blinkL==0){
blinkL=1;
blinkT=0;
PORTD=255;
digitalWrite(8,HIGH);
digitalWrite(9,HIGH);
}
if(blinkT==25&&blinkL==1){
blinkL=0;
blinkT=0;
PORTD=0;
digitalWrite(8,LOW);
digitalWrite(9,LOW);
}
}
}
// the loop function runs over and over again forever
void loop(){
//ib=0;
x=0;
while(swL==0){
delay(100);
time_n++;
if(time_n>30)time_n=21;
}
for(i=0;i<time_n;i++){
if(PDL==0){
digitalWrite(8,LOW);
digitalWrite(9,LOW);
PORTD = num[ib];
beep();
delay(x);
x=x+10;
ib++;
}
if(PBL==0){
PORTD = 0x00;
PORTB = num[ib];
beep();
delay(x);
x=x+10;
ib++;
if(ib>9){
ib=0;
PDL=0;
PBL=1;
}
}
if(ib>7){
PDL=1;
PBL=0;
}
numL=0;
}
}
void beep(){
int i_b;
for(i_b=0;i_b<5;i_b++){
digitalWrite(A3,HIGH);
delayMicroseconds(1000);
digitalWrite(A3,LOW);
delayMicroseconds(1000);}
}
ไม่มีความคิดเห็น:
แสดงความคิดเห็น