[Tutor] Help needed

Tom Brodle tbrodle at hotmail.com
Thu Feb 4 18:26:26 EST 2016

I am very new  to Python.  I am just practicing code using a simple plug board.  The code is working as I want it to but the last message and the original looping makes me have questions.  Because the main code works I will just abbreviate it.

import GPIO
import time
Gpio setmode (BCM)
led_pin = 18
GPIO setup(led_pin, GPIO)

        While true:
            Turn LED on
            sleep 5 seconds
            Turn LED off
            sleep .5 seconds  # program was initially designed to keep LED turning on and off and that worked.
                                           # Coming from the world of Basic I did/do not understand what made the program loop
                                           # back to while True: line of code.
                                           # I  wanted the LED to turn on and then off and stay off, so from some Python.org 
                                           # page I became aware of quit(code=None) and inserted it before the line Print("Cleaning up")                  quit(code=None)            # I put this line in to stop the looping back to While true:.                    
    Print("Cleaning up")
    GPIO.cleanup()           # I was told to put this line in but I do not know where it goes to do whatever. 
                                          #The code did turn the LED on once and then it did stay off, but it gave me a message that 
                                          # the  program is still running.  I did not think that programs actually did stop until the
                                          # power was removed.


More information about the Tutor mailing list