This should compile using gcc, if you're not interested in the C++ warts in
that code . . . Although for a modern version of gcc, you may have to
explicitly include another header or two.
#include <stdio.h>
#include <unistd.h>
int main(){
printf("LED Flash Start\n");
FILE *LEDHandle = NULL;
const char *LEDBrightness="/sys/class/leds/beaglebone:green:usr0/brightness";
for(int i=0; i<10; i++){
if((LEDHandle = fopen(LEDBrightness, "r+")) != NULL){
fwrite("1", sizeof(char), 1, LEDHandle);
fclose(LEDHandle);
}
usleep(1000000);
if((LEDHandle = fopen(LEDBrightness, "r+")) != NULL){
fwrite("0", sizeof(char), 1, LEDHandle);
fclose(LEDHandle);
}
usleep(1000000);
}
printf("LED Flash End\n");
}
On Mon, Nov 30, 2015 at 9:42 PM, William Hermans <[email protected]> wrote:
> By the way, no idea why that code is compiled in g++, or uses the using
> keyword. Because it's all C. Well, it does use cout for stdout too I
> suppose, but the code uses C style strings, instead of the C++ string
> classes . . .
>
> On Mon, Nov 30, 2015 at 9:39 PM, William Hermans <[email protected]>
> wrote:
>
>> Probably because the OS think it still has control of that LED - And
>> rightly so(because it does ). So disable the heartbeat pattern on USR0
>> *first* then try again. Also, if you're not running that app as root, or
>> sudo. It could fail silently, or possibly seg fault. The following disables
>> the heartbeat pattern:
>>
>> $ ls /sys/class/leds/beaglebone:green:usr0
>> brightness device max_brightness power subsystem trigger uevent
>> $ sudo su
>> # echo "none" > /sys/class/leds/beaglebone:green:usr0/trigger
>>
>>
>> On Mon, Nov 30, 2015 at 8:09 PM, <[email protected]> wrote:
>>
>>> Hello,
>>>
>>> I have been going through these steps:
>>> http://elinux.org/Beagleboard:C/C%2B%2B_Programming
>>>
>>> I have successfully ssh'd into my BeagleBone Black using MobaXterm and
>>> typed the code in the above link into a file (I have tried this with geddit
>>> and nano now and get the same results with both). The code is supposed to
>>> write "LED Flash Start" to the terminal, flash USR0 on the board 10 times,
>>> and then write "LED Flash Finish". The code compiles fine and when it runs
>>> it displays "LED Flash Start", waits for awhile, and then displays "LED
>>> Flash Finish" but the USR0 never changes from it's usual heartbeat flashing
>>> pattern. Any ideas on why the USR0 LED doesn't work as it should?
>>>
>>> Thanks in advance.
>>>
>>> --
>>> For more options, visit http://beagleboard.org/discuss
>>> ---
>>> You received this message because you are subscribed to the Google
>>> Groups "BeagleBoard" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to [email protected].
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>
--
For more options, visit http://beagleboard.org/discuss
---
You received this message because you are subscribed to the Google Groups
"BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.