Everything OFF

Easily turn off everything with one script. (intergarte all of the existing OFF scripts into one script)

Open an editor window using:

Then paste in the following text and save the file using CTRL-X and then Y and then ENTER.

Now run any of the existing led_on script, and turn it off using the following command:

The LED will turn off, and the following warning message will be displayed.
all_off.py:5: RuntimeWarning: This channel is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings.
GPIO.setup(13, GPIO.OUT) ## Setup GPIO Pin 13 to OUT (Green)

To disable warnings, simply include the following line to the script:

..right under:  GPIO.output(22,False) ## Turn on GPIO pin 22

Should look like this:

Run the script again, and no warning message will be displayed.

 

Accessing Command-Line Arguments(sys.argv):

The Python sys module provides access to any command-line arguments via the sys.argv. This serves two purpose:

  • sys.argv is the list of command-line arguments.
  • len(sys.argv) is the number of command-line arguments.

Here sys.argv[0] is the program ie. script name.

Example:

Open an editor window using:

Then paste in the following text and save the file using CTRL-X and then Y and then ENTER.

Run the above script as follows:

This will produce following result:
Number of arguments: 4 arguments.
Argument List: ['test.py', 'arg1', 'arg2', 'arg3']
Set the RGB LED colors on Your EduBoard with only one script using the “Python sys module”.

 

LED ON/OFF with sys.argv:

The following example shows the usage of the “sys module”.

Open an editor window using:

Then paste in the following text and save the file using CTRL-X and then Y and then ENTER.

Now run above script as follows:

This will produce following result:
The LED will lit blue (connected to GPIO pin 11)
To turn it off, run the script as follows:

To lit the LED green,(connected to GPIO pin 13) run the script as follows:

and to lit the LED red,(connected to GPIO pin 15) run the script as follows:

You don’t need to turn off any of the colour before you can lit another.

 

 Next Tutorial (Input, Button function)