-
Notifications
You must be signed in to change notification settings - Fork 0
/
gpio.cpp
59 lines (46 loc) · 1.2 KB
/
gpio.cpp
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
#include <stdio.h>
#include <stdlib.h>
#include <bcm2835.h>
#define PIN0 RPI_V2_GPIO_P1_13
#define PIN1 RPI_V2_GPIO_P1_07
#define POUT0 RPI_V2_GPIO_P1_11
#define POUT1 RPI_V2_GPIO_P1_15
int main(int argc, char **argv)
{
if (!bcm2835_init()) return 1;
bcm2835_gpio_fsel(PIN0, BCM2835_GPIO_FSEL_INPT);
bcm2835_gpio_fsel(PIN1, BCM2835_GPIO_FSEL_INPT);
bcm2835_gpio_set_pud(PIN0, BCM2835_GPIO_PUD_UP);
bcm2835_gpio_set_pud(PIN1, BCM2835_GPIO_PUD_UP);
bcm2835_gpio_fsel(POUT0, BCM2835_GPIO_FSEL_OUTP);
bcm2835_gpio_fsel(POUT1, BCM2835_GPIO_FSEL_OUTP);
while (1)
{
uint8_t in0 = bcm2835_gpio_lev(PIN0);
uint8_t in1 = bcm2835_gpio_lev(PIN1);
if (in0 == 0)
{
bcm2835_gpio_write(POUT0, HIGH);
}
else
{
bcm2835_gpio_write(POUT0, LOW);
}
if (in1 == 0) break;
}
for (int i=0; i<5; i++)
{
bcm2835_gpio_write(POUT0, HIGH);
bcm2835_delay(500);
bcm2835_gpio_write(POUT0, LOW);
bcm2835_gpio_write(POUT1, HIGH);
bcm2835_delay(500);
bcm2835_gpio_write(POUT0, HIGH);
bcm2835_delay(500);
bcm2835_gpio_write(POUT0, LOW);
bcm2835_gpio_write(POUT1, LOW);
bcm2835_delay(500);
}
bcm2835_close();
return 0;
}