-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathblink_24_and_25.cpp
46 lines (39 loc) · 1.54 KB
/
blink_24_and_25.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
//Blink raspberry pi gpio outputs 24 and 25. Connect the LED to the pin in series with a 200 ohm resistor. The other end of the LED connects to ground. Green LED is connected to out25. Red LED is connected to out25
//Works for raspberry pi 4 or 5. Change the gpiochip number for the appropriate board.
#include <gpiod.h>
#include <iostream>
#include <unistd.h>
int main() {
gpiod_chip *chip;
gpiod_line *line_24, *line_25;
const char *chipname = "gpiochip4"; // Modify this if needed for your Pi version
const unsigned int line_offset_24 = 24;
const unsigned int line_offset_25 = 25;
chip = gpiod_chip_open_by_name(chipname);
if (!chip) {
std::cerr << "Could not open chip." << std::endl;
return 1;
}
line_24 = gpiod_chip_get_line(chip, line_offset_24);
line_25 = gpiod_chip_get_line(chip, line_offset_25);
if (!line_24 || !line_25) {
std::cerr << "Could not get line." << std::endl;
gpiod_chip_close(chip);
return 1;
}
if (gpiod_line_request_output(line_24, "blinktest", 0) < 0 || gpiod_line_request_output(line_25, "blinktest", 0) < 0) {
std::cerr << "Could not set line as output." << std::endl;
gpiod_chip_close(chip);
return 1;
}
while (true) {
gpiod_line_set_value(line_24, 1);
gpiod_line_set_value(line_25, 1);
usleep(500000); // 500ms delay
gpiod_line_set_value(line_24, 0);
gpiod_line_set_value(line_25, 0);
usleep(500000); // 500ms delay
}
gpiod_chip_close(chip);
return 0;
}