Ronicus
Posts: 21
Joined: Sat May 06, 2017 7:34 am

While loop issues(Solved)

Sat Aug 12, 2017 2:10 am

Is this code wrong ? It wont blink my LED

Code: Select all

count = 0
while (count < 7):
        GPIO.output(40,True) ## Turn on GPIO pin 21
        GPIO.output(38,True) ## Turn on GPIO pin 20
        time.sleep(.2)
        GPIO.output(40,False) ## Turn off GPIO 21
        GPIO.output(38,False) ## Turn off GPIO 20
        count = count + 1
Last edited by Ronicus on Sat Aug 12, 2017 11:52 am, edited 1 time in total.

User avatar
OutoftheBOTS
Posts: 118
Joined: Tue Aug 01, 2017 10:06 am

Re: While loop issues

Sat Aug 12, 2017 5:16 am

I assume that the LED stays on the while time for 7 * 0.2 secs (1.4sec)

If you loom at your code it turns on the LED then waits 0.2 sec then turns off the LED but as soon as it is turned off it loops around agian and turns it back on. U need to add another wait of 0.2secvs after you turn off the LED before it loops around again :)

Ronicus
Posts: 21
Joined: Sat May 06, 2017 7:34 am

Re: While loop issues

Sat Aug 12, 2017 11:52 am

OutoftheBOTS wrote:
Sat Aug 12, 2017 5:16 am
I assume that the LED stays on the while time for 7 * 0.2 secs (1.4sec)

If you loom at your code it turns on the LED then waits 0.2 sec then turns off the LED but as soon as it is turned off it loops around agian and turns it back on. U need to add another wait of 0.2secvs after you turn off the LED before it loops around again :)
Spot on man thanks for the help :)

Return to “Python”

Who is online

Users browsing this forum: No registered users and 9 guests