-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.c
69 lines (54 loc) · 1.54 KB
/
game.c
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "def.h"
//definition de btn
#define SWITCH_1 PORTBbits.RB6
#define SWITCH_2 PORTBbits.RB7
char SW1_time = 0;
char SW2_time = 0;
char old_SW1_time = 0;
char old_SW2_time = 0;
int SW1_state = 0;
int SW2_state = 0;
int old_SW1_state = 0;
int old_SW2_state = 0;
int i1 = 0;
int i2 = 0;
//int compteur = 10; //compteur=0 joureur 1 gagne compteur=20 joureur 2 gagne
int delay_debounce = 10; //a modifier
void init_port(){
TRISBbits.TRISB6 = 1; //entrée pour les switchs
TRISBbits.TRISB7 = 1;
}
void partie(){
millis = 0;
while (en_cours == 1){
old_SW1_state = SW1_state;
old_SW2_state = SW2_state;
SW1_state = PORTBbits.RB6;
SW2_state = PORTBbits.RB7;
if (SW1_state != old_SW1_state){
old_SW1_time = SW1_time;
SW1_time = millis;
if (SW1_time - old_SW1_time < delay_debounce){
SW1_state = !SW1_state;
}else{
if (SW1_state == 1){
compteur = compteur-1;
}
}
}
if (SW2_state != old_SW2_state){
old_SW2_time = SW2_time;
SW2_time = millis;
if (SW2_time - old_SW2_time < delay_debounce){
SW2_state = !SW2_state;
}else{
if (SW2_state ==1){
compteur = compteur+1;
}
}
}
if (compteur==0 || compteur==20){
en_cours = 0;
}
}
}