-
Notifications
You must be signed in to change notification settings - Fork 0
/
roleta.ino
63 lines (58 loc) · 1.29 KB
/
roleta.ino
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
// Parametros:
int num_leds = 16; // Quantidade de LEDs
int fast = 100; // Velocidade (Quanto maior mais lento)
int slow_down = 5; // Desaceleraçao (Quanto maior mais lento)
float slow_lap = 1.5; // Voltas des Desaceleraçao
int min_lap = 2; // Minimo de voltas
int max_lap = 4; // Maximo de voltas
int start_led = 30;
int end_led = start_led + num_leds;
int button = 3;
int buzzer = 2;
int led;
void turn(int num){
int cont = num;
int cont2 = 0;
led=start_led;
while(cont > 0){
digitalWrite(led, 0);
led++;
if (led == end_led){
led = start_led;
}
tone(buzzer, 200, 80);
digitalWrite(led, 1);
delay(fast+cont2);
if(cont< (num_leds*slow_lap)){
cont2 += slow_down;
}
Serial.print("Led ");
Serial.print(led);
Serial.println(" ligado.");
cont--;
}
}
void clean(){
for(led=start_led;led<end_led;led++){
digitalWrite(led, 0);
}
}
void setup() {
Serial.begin(9600);
Serial.println("Iniciando....");
for(led=start_led;led<end_led;led++){
pinMode(led, OUTPUT);
Serial.print("Led ");
Serial.print(led);
Serial.println(" ativado.");
}
pinMode(buzzer, OUTPUT);
pinMode(button, INPUT);
}
void loop() {
if(digitalRead(button)==1){
clean();
turn(random(num_leds*min_lap,num_leds*max_lap));
delay(50);
}
}