I wrote a C++ program to control pins turning on or off, the program is shown as following:
Figure 1: C++ code for driving the fish feeder
A infinite loop is used to feed fish all time, and first output a high pulse from pin 11 to drive the feeder rotating for about 9.325s, which is the time for rotating one cycle. Then set the pin is low so that the feeder is idle. After that, set the pin being high again and so on.
Then put it in the Raspberry Pi and compile it using the following command,
$g++ Blink.cpp -o Blink -lwiringPi
And then run it using the following command,
$sudo ./Blink
The results can be shown in following video:
Video 1: Video for controlling feeder using C++
It shows that the feeder rotates successfully, so this can be used to control GPIO pins using C++.
No comments:
Post a Comment