[Tutor] Help needed
Joel Goldstick
joel.goldstick at gmail.com
Thu Feb 4 19:13:19 EST 2016
On Thu, Feb 4, 2016 at 6:26 PM, Tom Brodle <tbrodle at hotmail.com> wrote:
> 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)
>
> try:
> While true:
>
Actually you need:
While True:
This means run forever. In the while loop you need some test to break or
this loop will run forever. You can press Ctl-C to quit the program
> 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.
>
> Thanks
> Tom
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
--
Joel Goldstick
http://joelgoldstick.com/stats/birthdays
More information about the Tutor
mailing list