0

Help with code. Adafruit Trinket MO
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Help with code. Adafruit Trinket MO

by JKracht on Mon Sep 27, 2021 4:32 pm

New to any type of programming, I was wondering if anyone can tell me why I cant get the second half of this code to run (lines 14-23). Any help would be appreciated and if anyone has any suggestions to the best place to learn more.
Thanks!
Attachments
Light Circuit.py
(437 Bytes) Downloaded 2 times

JKracht
 
Posts: 4
Joined: Mon Sep 27, 2021 4:25 pm

Re: Help with code. Adafruit Trinket MO

by adafruit_support_carter on Mon Sep 27, 2021 4:46 pm

You have two infinite loops. Only the first one is being run:
Code: Select all | TOGGLE FULL SIZE
while True:
    led.value = True
    time.sleep(2.0)
    led.value = False
    time.sleep()

Nothing after that is ever reached.

adafruit_support_carter
 
Posts: 21396
Joined: Tue Nov 29, 2016 2:45 pm

Re: Help with code. Adafruit Trinket MO

by JKracht on Mon Sep 27, 2021 6:10 pm

How do I stop the infinite loop?

JKracht
 
Posts: 4
Joined: Mon Sep 27, 2021 4:25 pm

Re: Help with code. Adafruit Trinket MO

by adafruit_support_carter on Mon Sep 27, 2021 6:31 pm

You can stop the entire code from running by using <CTRL><C>, but that's probably not what you are after.

What are you trying to get the code to do?

adafruit_support_carter
 
Posts: 21396
Joined: Tue Nov 29, 2016 2:45 pm

Re: Help with code. Adafruit Trinket MO

by JKracht on Mon Sep 27, 2021 6:38 pm

I'm trying to get the code to run function 1
while True:
led.value = True
time.sleep(2.0)
led.value = False
time.sleep()
then stop and then just run the second part, after the first one has shut off
while True:
led.value = False
time.sleep(3.0)
led.value = True
time.sleep(1.0)
led.value = False
time.sleep()
basically to just control a relay and shut off then control a second one and shut off.

JKracht
 
Posts: 4
Joined: Mon Sep 27, 2021 4:25 pm

Re: Help with code. Adafruit Trinket MO

by adafruit_support_carter on Mon Sep 27, 2021 7:03 pm

You want those actions to happen only once?

adafruit_support_carter
 
Posts: 21396
Joined: Tue Nov 29, 2016 2:45 pm

Re: Help with code. Adafruit Trinket MO

by JKracht on Tue Sep 28, 2021 9:27 am

Yes

JKracht
 
Posts: 4
Joined: Mon Sep 27, 2021 4:25 pm

Re: Help with code. Adafruit Trinket MO

by adafruit_support_carter on Tue Sep 28, 2021 11:16 am

Then the loops probably are not needed.

then stop and then just run the second part, after the first one has shut off


What determines when the first one has shut off? Do you need to wait for something before the second part is run? Or can the second part run immediately after the first?

adafruit_support_carter
 
Posts: 21396
Joined: Tue Nov 29, 2016 2:45 pm

Please be positive and constructive with your questions and comments.