Commit 004b9394a11b8da612750b2a9697aa227b22cb48
1 parent
b08b30f4
Avant début piste
Showing
4 changed files
with
33 additions
and
22 deletions
Show diff stats
tests/atmega2560/ledControl/ledControl.c
... | ... | @@ -2,8 +2,10 @@ |
2 | 2 | #include <util/delay.h> |
3 | 3 | #include <math.h> |
4 | 4 | |
5 | +#include "tlc5947.h" | |
6 | + | |
5 | 7 | #define NB_DRIVERS 3 |
6 | -#define MAX_VALUE 85 //TODO tbd ! | |
8 | +#define MAX_VALUE 80 //TODO tbd ! | |
7 | 9 | #define DELAY 100 |
8 | 10 | |
9 | 11 | int main(void){ |
... | ... | @@ -16,15 +18,15 @@ int main(void){ |
16 | 18 | while(1){ |
17 | 19 | // Build animation |
18 | 20 | for(int i=0; i<NB_DRIVERS * DLED_CHANNELS; i++){ |
19 | - double sinIn = (double) animTick / 8; | |
20 | - unsigned int val = (unsigned int) (0.5 + (sin(sinIn) * 0.5)); | |
21 | - ledValues[i] = val * MAX_VALUE; | |
21 | + double val = (double) (animTick % 21) / 20; | |
22 | + ledValues[i] = (unsigned int) (val * MAX_VALUE); | |
22 | 23 | } |
24 | + | |
23 | 25 | animTick++; |
24 | 26 | if(animTick >= 10000) |
25 | 27 | animTick = 0; |
26 | 28 | |
27 | - set_LED_Drivers(groupes, NB_DRIVERS); | |
29 | + set_LED_Drivers(ledValues, NB_DRIVERS); | |
28 | 30 | _delay_ms(100); |
29 | 31 | } |
30 | 32 | return 0; | ... | ... |
tests/atmega2560/ledControl/makefile
tests/atmega2560/ledControl/tlc5947.c
1 | 1 | #include <avr/io.h> |
2 | + | |
2 | 3 | #include "tlc5947.h" |
3 | 4 | |
4 | -#define DLED_CHANNELS 24 | |
5 | +#define DDR_DLED_CLOCK DDRE | |
6 | +#define PORT_DLED_CLOCK PORTE | |
7 | + | |
8 | +#define DDR_DLED_DATA DDRG | |
9 | +#define PORT_DLED_DATA PORTG | |
5 | 10 | |
6 | -#define DDR_DLED DDRD | |
7 | -#define PORT_DLED PORTD | |
11 | +#define DDR_DLED_LATCH DDRB | |
12 | +#define PORT_DLED_LATCH PORTB | |
8 | 13 | |
9 | -#define PIN_DLED_CLOCK 5 | |
10 | -#define PIN_DLED_DATA 4 | |
11 | -#define PIN_DLED_LATCH 6 | |
14 | +#define PIN_DLED_CLOCK 0x08 | |
15 | +#define PIN_DLED_DATA 0x20 | |
16 | +#define PIN_DLED_LATCH 0x10 | |
12 | 17 | |
13 | 18 | void init_LED_Drivers(int nb){ |
14 | 19 | // LED drivers I/O as outputs |
15 | - DDR_DLED |= (1<<PIN_DLED_CLOCK) | (1<<PIN_DLED_DATA) | (1<<PIN_DLED_LATCH); | |
20 | + DDR_DLED_CLOCK |= PIN_DLED_CLOCK; | |
21 | + DDR_DLED_DATA |= PIN_DLED_DATA; | |
22 | + DDR_DLED_LATCH |= PIN_DLED_LATCH; | |
16 | 23 | // Set LATCH output low |
17 | - PORT_DLED &= ~(1<<PIN_DLED_LATCH); | |
24 | + PORT_DLED_LATCH &= ~PIN_DLED_LATCH; | |
18 | 25 | } |
19 | 26 | |
20 | 27 | |
21 | 28 | void set_LED_Drivers(unsigned int pwm[], int nb){ |
22 | 29 | // Set LATCH output low |
23 | - PORT_DLED &= ~(1<<PIN_DLED_LATCH); | |
30 | + PORT_DLED_LATCH &= ~PIN_DLED_LATCH; | |
24 | 31 | // 24 channels per TLC5947 |
25 | 32 | int i; |
26 | 33 | for(i=DLED_CHANNELS*nb-1; i>=0; i--){ |
... | ... | @@ -29,24 +36,24 @@ void set_LED_Drivers(unsigned int pwm[], int nb){ |
29 | 36 | int j; |
30 | 37 | for(j=0; j<12; j++){ |
31 | 38 | // Set CLOCK output low |
32 | - PORT_DLED &= ~(1<<PIN_DLED_CLOCK); | |
39 | + PORT_DLED_CLOCK &= ~PIN_DLED_CLOCK; | |
33 | 40 | |
34 | 41 | // Set DATA as stated by bit #j of i |
35 | 42 | if(v & 0x0800) |
36 | - PORT_DLED |= (1<<PIN_DLED_DATA); | |
43 | + PORT_DLED_DATA |= PIN_DLED_DATA; | |
37 | 44 | else |
38 | - PORT_DLED &= ~(1<<PIN_DLED_DATA); | |
45 | + PORT_DLED_DATA &= ~PIN_DLED_DATA; | |
39 | 46 | |
40 | 47 | // Set CLOCK output HIGH |
41 | - PORT_DLED |= (1<<PIN_DLED_CLOCK); | |
48 | + PORT_DLED_CLOCK |= PIN_DLED_CLOCK; | |
42 | 49 | v <<= 1; |
43 | 50 | } |
44 | 51 | } |
45 | 52 | // Set CLOCK output low |
46 | - PORT_DLED &= ~(1<<PIN_DLED_CLOCK); | |
53 | + PORT_DLED_CLOCK &= ~PIN_DLED_CLOCK; | |
47 | 54 | |
48 | 55 | // Set LATCH output high |
49 | - PORT_DLED |= (1<<PIN_DLED_LATCH); | |
56 | + PORT_DLED_LATCH |= PIN_DLED_LATCH; | |
50 | 57 | // Set LATCH output low |
51 | - PORT_DLED &= ~(1<<PIN_DLED_LATCH); | |
58 | + PORT_DLED_LATCH &= ~PIN_DLED_LATCH; | |
52 | 59 | } | ... | ... |