led.cc 1.06 KB
Newer Older
Gunter Windau's avatar
azmq rm    
Gunter Windau committed
1
#include "led.h"
Your Name's avatar
Your Name committed
2
#include <pigpio.h>
Gunter Windau's avatar
azmq rm    
Gunter Windau committed
3
4
5
6
7

#include <stdlib.h>
#include <unistd.h>
#include <iostream>

8
9
static int nled = 0;
static const int *ledgpio = 0;
Gunter Windau's avatar
azmq rm    
Gunter Windau committed
10
11
12

void playleds();

13
void initleds(int _nled, const int *_ledgpio)
Gunter Windau's avatar
azmq rm    
Gunter Windau committed
14
{
15
16
    nled = _nled;
    ledgpio = _ledgpio;
Gunter Windau's avatar
azmq rm    
Gunter Windau committed
17
18
    for (int i=0; i<nled; i++)
    {
Your Name's avatar
Your Name committed
19
       gpioSetMode(ledgpio[i], PI_OUTPUT);
Gunter Windau's avatar
azmq rm    
Gunter Windau committed
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
    }
    playleds();
}

void playleds()
{
    for (int i=0; i<nled; i++)
    {
       setled(i, 1);
       usleep(200000);
    }
    for (int i=0; i<nled; i++)
    {
       setled(i, 0);
       usleep(200000);
    }
    for (int i=0; i<nled; i++)
    {
       setled(i, 1);
    }
    usleep(500000);
    for (int i=0; i<nled; i++)
    {
       setled(i, 0);
    }
    usleep(500000);
    for (int i=0; i<nled; i++)
    {
       setled(i, 1);
    }
    usleep(500000);
    for (int i=0; i<nled; i++)
    {
       setled(i, 0);
    }
}


void setled(int lednr, int value)
{
   int bit;
   if (value)
      bit = 1;
   else
      bit = 0;
 
Your Name's avatar
Your Name committed
66
67
68
69
70
71
   int r= gpioWrite(ledgpio[lednr], bit);
   if (r < 0)
   {
      perror("gpioWrite");
      exit(1);
   }
Gunter Windau's avatar
azmq rm    
Gunter Windau committed
72
}