On the 2410 + LINUX Platform, a simple application of LED

Source: Internet
Author: User

// Led. c

 

# Include <stdio. h>
# Include <stdlib. h>
# Include <unistd. h>
# Include <sys/IOCTL. h>

Int main (INT argc, char ** argv)
{
Int on;
Int led_no;
Int FD;
 
/* Check the two parameters of LED control. Exit if no parameter is input. */
If (argc! = 3 | sscanf (argv [1], "% d", & led_no )! = 1 | sscanf (argv [2], "% d", & on )! = 1 | on <0 | on> 1
| Led_no <0 | led_no> 3)
{
Fprintf (stderr, "Usage: LEDs led_no 0 | 1/N ");
Exit (1 );
}
 
/* Open the/dev/LEDs Device File */
FD = open ("/dev/LEDs", 0 );
If (FD <0)
{
Perror ("open device LEDs ");
Exit (1 );
}
 
/* Control the led by calling IOCTL and input parameters */
IOCTL (FD, on, led_no );
 
/* Close the device handle */
Close (FD );
Return 0;
}

 

 

The above is the source code.

The command for compiling in a Linux virtual machine is: Arm-Linux-gcc-O led. c

 

After compilation, It is uploaded to the target board through FTP.

 

At this time, you can use a Super Terminal or telnet to the console on the target board to view the file led.

The LED cannot be executed. The command chmod A + x LED is used to run the LED file.

 

According to the source program, we can use the LEDs led_no 0 | 1 method to start the application to control the LED lighting and quenching.
Led_no is the led to be operated (can be 0, 1, 2, 3), 0 and 1 respectively indicate to close and light up.
# Led 2 1
Will light up led3

 

It is worth noting that the source generation has been downloaded to the target board and the application is started with an additional sample.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.