-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbitCounter.ino
82 lines (73 loc) · 1.36 KB
/
bitCounter.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <stdlib.h>
#include <stdio.h>
#define LED_WHITE 5
#define LED_BLUE 6
#define LED_GREEN 7
#define LED_YELLOW 8
#define LED_RED 9
#define DIT 200
#define DAH (DIT * 3)
void setup() {
for (int pin = LED_WHITE; pin <= LED_RED; ++pin) {
pinMode(pin, OUTPUT);
}
}
int *get_bits(int numero, int quantidadeBits){
int *mapa = malloc(sizeof(int) * quantidadeBits);
for(int posicao = 0; posicao < quantidadeBits; ++posicao){
int mascara = 1 << posicao;
int mascaraPosicao = numero & mascara;
int situacaoBit = mascaraPosicao >> posicao;
mapa[posicao] = situacaoBit;
}
return mapa;
}
/*
0 00000
1 00001
2 00010
3 00011
4 00100
5 00101
6 00110
7 00111
8 01000
9 01001
10 01010
11 01011
12 01100
13 01101
14 01110
15 01111
16 10000
17 10001
18 10010
19 10011
20 10100
21 10101
22 10110
23 10111
24 11000
25 11001
26 11010
27 11011
28 11100
29 11101
30 11110
31 11111
*/
void loop() {
int quantidadeBits = 8;
int quantidadeLEDs = 5;
int limite = 32;
for (int numero = 0; numero < limite; ++numero) {
int led = 0;
int *mapa = get_bits(numero, quantidadeBits);
for (int posicao = quantidadeLEDs; posicao > 0; --posicao) {
int pin = LED_WHITE + led;
digitalWrite(pin, mapa[posicao - 1]);
++led;
}
delay(DIT);
}
}