Full width home advertisement

Arduino project

Raspberry project

Post Page Advertisement [Top]

Control leds on mini2440 by a Qt Creator's program

Mini2440 board has four leds that is used to indicate the status of the board. Normally, the leds will run when led service is loaded. However, we can use command to stop or restart that led service, they are:$/etc/rc.d/init.d/leds stop(after this command, leds will stop blinking)$/etc/rc.d/init.d/leds start(after this command, leds will start blinking)
I wrote a QtCreator's program that passes those two commands by pressing button, the leds will stop or start running then. The source code of that program can be found atlink here.
In Qt, there are two things you should know, they are "slot" and "signal". For example, when you press on button, it means you give a "signal"; then, that "signal" will trigger (all thing in) a "slot".

So, when you press (click) the pushButton_2 (giving a "signal"), then the sub-program ("slot") named MainWindow::on_pushButton_2_clicked() will run.
I just briefly introduce about programming in Qt, for more deeply in this issue, please take more day in book. My book at the first day programming Qt is "C++ GUI programming with qt4" (author: Jasmin Blanchette and Mark Summerfield), it is easy for newcomer, hope it will help you too.

Leds on mini2440 is controlled by device driver located at /dev/leds. So, we just open that file, pass it some data, that's it, the leds will light or not as in received data.
For example, in the source code, open the file and write data in order to control leds:int fd;
if((fd=open("/dev/leds", 0))<0){
::close(fd);
return;
}
ioctl(fd,0,0); //led0 off
ioctl(fd,0,1); //led1 off

Once again, to understand more, we have to work with book again. There is a excellent book that i found, it is "Unix System Programming" by Keith Haviland, Ben Salama. This book will teach us how to open, write, delete, ... a file, and more.
And here, here is my program running in mini2440 board