Bb_black_ Study Notes-(4) Flashing LED shell command

Source: Internet
Author: User

Previous note in the terminal Input shell command to achieve the LED lights and off, as a beginner, has been excited for a while, because finally has a 0 breakthrough. Manual light led always more trouble, or through the program let it go to light and extinguished, so that it is more fun. In this note, I learn the shell script to realize the flashing of the LED, so it is fun. This note is first seen from the phenomenon, and then in the analysis of its implementation principle.

First step: Realize led Flashing

1. Start with a simple shell script to learn about the use of shell scripts. To create a shell script named Hello_sh to edit the execution process.

A few notes:

(1) The shell script may not have the file suffix name, but for convenience, you can add. sh as a prefix. Use _sh as the expression, also can not;

(2) Shell script creation can be created using touch filename;

(3) Edit shell script can directly use the VI editor, about the VI editor of the Simple and practical view of the previous note;

(4) Shell scripts do not need to compile to run, there is shell interpreter to complete the interpretation and execution of the command;

(5) The new shell script needs to add executable permissions, otherwise it will execute error;

(6) Run the shell script directly using./* to run;

(7) In the Hello_sh script file there is only one line of content, the purpose is to output the Hello character, script content such as.

2, the following to enter today's theme, first or to manually create a shell script file, the author's file name is Led_sh. The process of creating and adding permissions is not posted here, please refer to above. The contents of Led_sh are posted directly below.

A few notes:

(1) For detailed use of the shell, please refer to this link http://c.biancheng.net/cpp/shell/. This site has a streamlined shell tutorial, for beginners to get started is very fast;

(2) briefly explain the contents of the script:

1) Line 1th: Display the Hello led a string of characters at the terminal;

2) Line 2nd to 4th: This part is an if statement, the purpose is to see if there is a gpio44 file, if not, through the 3rd line of the script to add one;

3) Line 4th: Add output attributes for gpio44;

4) Line 7th to 13th: This part is a while statement, in the while statement light led, then sleep 0.25 seconds to extinguish the LED, and then sleep 0.25 seconds. So nonstop cycle.

5) Line 14th: Turn off the LED light.

3, through the VI editor input the above script, and then run, you can see the LED light flashing state. The phenomenon is the same as the previous one, but this time the script can be run with constant flicker.

Step Two: Learn a simple shell script

1, Echo Usage Previous note has been explained, here no longer explain.

2, if usage.

The IF statement determines which branch to execute by using relational operators to determine whether an expression is true or false. There are three uses of the IF statement, which only shows the simplest syntax, if ... else statement:

1 if  2     ifistrue3 fi

A few notes:

(1) If expression returns True,then, the statement is executed and no statement is executed if False is returned.

(2) finally must end with FI to close the if,fi is if the inverted spelling.

(3) There must be a space between expression and square brackets ([]), otherwise there will be a syntax error.

3, while usage.

The while loop is used to continuously execute a series of commands and to read data from the input file; the command is usually a test condition. The format is:

 while Command  do    if  is true  Done

A few notes:

(1) The command is completed, the control returns to the top of the loop, from the beginning until the test condition is false, otherwise do not exit;

(2) The contents of the loop body are contained between the Do......done.

Bb_black_ Study Notes-(4) Flashing LED shell command

Related Article

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.