검색결과 리스트
글
BeagleBone Black – Controlling user LEDs using C/C++
from : http://learnbuildshare.wordpress.com/2013/05/19/beaglebone-black-controlling-user-leds-using-c/
The $45 BeagleBone Black is here! With all its GPIO ports, it can be a great tool for robotics projects. It ships with javascript example code (in the Cloud9 IDE). There are many examples on the internet showing pin manipulation with javascript and python. There are lots of examples on pin manipulation from the terminal. Unfortunately for a new BBB owner, I could only find suggestions on how to do this on C/C++. I could not find a complete, short, and plain C/C++ example which I could just copy and use as a starting point…something like the traditional “blink” example. Some people have posted their own C++ libraries for pin manipulation, but I find that confusing without understanding the basic concepts.
After a lot of digging, ssh-ing, and g++-ing, I finally got a “blink” example up and running on C++. Here it is. Hopefully, for all the new BBB users out there, this can serve as a starting point in understanding how to use the GPIO ports through C/C++.
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 | /******************************************************* * Example code for user LEDs on the new beaglebone * black running the Linux Angstrom distribution ******************************************************** * Instructions: * -Compile and run from the root directory * -For the older (white) beaglebone, change * "beaglebone:green:usr0" to "beaglebone::usr0" * * Code adapted from: * - Derek Molloy, "Beaglebone: C/C++ Programming * Introduction for ARM Embedded Linux Development * using Eclipse CDT" video tutorial, * (link: www.youtube.com/watch?v=vFv_-ykLppo) * - Mark A. Yoder, EBC Exercise 10 Flashing an LED * (link: "elinux.org/EBC_Exercise_10_Flashing_an_LED) *******************************************************/#include <stdio.h>#include <unistd.h>using namespace std;int main(int argc, char** argv) { FILE *LEDHandle = NULL; char *LEDBrightness = "/sys/class/leds/beaglebone:green:usr0/brightness"; printf("\nStarting simple LED blink program\n"); while(1){ if((LEDHandle = fopen(LEDBrightness, "r+")) != NULL){ fwrite("1", sizeof(char), 1, LEDHandle); fclose(LEDHandle); } sleep(0.3); if((LEDHandle = fopen(LEDBrightness, "r+")) != NULL){ fwrite("0", sizeof(char), 1, LEDHandle); fclose(LEDHandle); } sleep(0.8); } return 0;} |
# g++ led.cpp -o led
'board > beaglebone Black' 카테고리의 다른 글
| beagle bone can access the internet by using usb connection of host (0) | 2013.09.07 |
|---|---|
| Using BeagleBone Black GPIOs read by c (0) | 2013.09.05 |
| Using BeagleBone Black GPIOs by bash script (0) | 2013.09.05 |
| Using Eclipse to Cross-compile Applications for Embedded Systems 4 (0) | 2013.09.05 |
| Using Eclipse to Cross-compile Applications for Embedded Systems 3 (0) | 2013.09.05 |
