ELI70-CP
User’s Manual
8/4/2020
Copyright ©2020,
Future Designs, Inc.
Page
12
of
14
int
main
(
int
argc
,
char
*
argv
[]){
int
data
=
0
;
// Brightness level
if
(
argc
!=
2
){
// Give user correct usage if ran incorrectly
cout
<<
"Error: correct usage, brightness <value>"
<<
endl
;
return
1
;
}
data
=
stoi
(
argv
[
1
]);
if
(
data
>
RANGE
||
data
<
0
){
cout
<<
"Error: brightness value must be between 0 and "
<<
RANGE
<<
endl
;
return
1
;
}
if
(!
bcm2835_init
())
return
1
;
bcm2835_gpio_set_pad
(
BCM2835_PAD_GROUP_GPIO_0_27
,
BCM2835_PAD_DRIVE_2mA
);
//
Sets the drive current to 2mA
bcm2835_gpio_fsel
(
LED
,
BCM2835_GPIO_FSEL_ALT5
);
// Sets up pin 18 for alt5 pwm
mode
bcm2835_pwm_set_clock
(
CLOCK
);
// Sets pwm clock to 19.2 MHz / CLOCK
bcm2835_pwm_set_mode
(
0
,
1
,
1
);
// Sets mode to markspace
bcm2835_pwm_set_range
(
0
,
RANGE
);
// Sets range
bcm2835_pwm_set_data
(
0
,
data
);
// Sets data rate to argument value
bcm2835_close
();
return
0
;
}
Figure 7. Backlight Control for Raspberry Pi