ws2812b Wert zerlegen und nacheinander abfragen

OP #4042292
Lesenswert?

Hallo liebe Gemeinde,

ich habe vollgendes Problem.
Ich habe mir ein WS2812b Led Strip geleistet. Den LED probiere ich 
gerade anzusteuern. Leider mache ich das gerade auf ziemlich 
umständliche Art und Weise.

Das Timing habe ich so gelöst:
1
void output_null()
2
{
3
  PORTC |= (1<<PC0);
4
  asm volatile ("nop");
5
  asm volatile ("nop");
6
  asm volatile ("nop");
7
  asm volatile ("nop");
8
  asm volatile ("nop");
9
  PORTC &= ~(1<<PC0);
10
  asm volatile ("nop");
11
  asm volatile ("nop");
12
  asm volatile ("nop");
13
  asm volatile ("nop");
14
  asm volatile ("nop");
15
  asm volatile ("nop");
16
  asm volatile ("nop");
17
  asm volatile ("nop");
18
  asm volatile ("nop");
19
  asm volatile ("nop");
20
}
21

22
void output_eins()
23
{
24
  PORTC |= (1<<PC0);
25
  asm volatile ("nop");
26
  asm volatile ("nop");
27
  asm volatile ("nop");
28
  asm volatile ("nop");
29
  asm volatile ("nop");
30
  asm volatile ("nop");
31
  asm volatile ("nop");
32
  asm volatile ("nop");
33
  asm volatile ("nop");
34
  asm volatile ("nop");
35
  asm volatile ("nop");
36
  PORTC &= ~(1<<PC0);
37
  asm volatile ("nop");
38
  asm volatile ("nop");
39
  asm volatile ("nop");
40
  asm volatile ("nop");
41
}
42

43
void output_reset()
44
{
45
  _delay_us(50);
46
}

ist bestimmt nicht die Beste Art aber es Funktioniert erstmal.

wenn ich jetzt eine Led anspreche mache ich das so:
1
 while(1)
2
    {
3
    output_eins();
4
    output_eins();
5
    output_eins();
6
    output_eins();
7
    output_eins();
8
    output_eins();
9
    output_eins();
10
    output_eins();
11
    
12
    output_null();
13
    output_null();
14
    output_null();
15
    output_null();
16
    output_null();
17
    output_null();
18
    output_null();
19
    output_null();
20
    
21
    output_null();
22
    output_null();
23
    output_null();
24
    output_null();
25
    output_null();
26
    output_null();
27
    output_null();
28
    output_null();
29
    }

so da gibt es definitiv eine bessere Lösung und genau die will ich jetzt 
angehen.

Ich habe mir ein struct gemacht.
1
struct LED
2
{
3
  char _gruen;
4
  char _rot;
5
  char _blau;
6
};

dazu noch eine Funktion die dieses struct verwendet.
1
void output_send_led(struct LED _led)
2
{
3
  
4
}

jetzt aber zu meinen eigentlichen Problem und zwar wie schaffe ich es 
die Daten eins nach dem anderen rauszugeben.

wie macht man das am besten? Ich habe mir das so gedacht.
Erst schicke ich den gruen Wert dann den rot Wert und zum Schluss den 
blau Wert raus.

Ich komme aber nicht darauf, wie ich die sagen wir mal blau = 255 
zerlege und Prüfen kann ob jetzt eine eins oder eine null geschickt 
werden muss.

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren