Help with code. Adafruit Trinket MO

Adafruit's tiny microcontroller platform. Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
JKracht
 
Posts: 4
Joined: Mon Sep 27, 2021 4:25 pm

Help with code. Adafruit Trinket MO

Post by JKracht »

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 8 times

User avatar
adafruit_support_carter
 
Posts: 29168
Joined: Tue Nov 29, 2016 2:45 pm

Re: Help with code. Adafruit Trinket MO

Post by adafruit_support_carter »

You have two infinite loops. Only the first one is being run:

Code: Select all

while True:
    led.value = True
    time.sleep(2.0)
    led.value = False
    time.sleep()
Nothing after that is ever reached.

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

Re: Help with code. Adafruit Trinket MO

Post by JKracht »

How do I stop the infinite loop?

User avatar
adafruit_support_carter
 
Posts: 29168
Joined: Tue Nov 29, 2016 2:45 pm

Re: Help with code. Adafruit Trinket MO

Post by adafruit_support_carter »

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?

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

Re: Help with code. Adafruit Trinket MO

Post by JKracht »

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.

User avatar
adafruit_support_carter
 
Posts: 29168
Joined: Tue Nov 29, 2016 2:45 pm

Re: Help with code. Adafruit Trinket MO

Post by adafruit_support_carter »

You want those actions to happen only once?

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

Re: Help with code. Adafruit Trinket MO

Post by JKracht »

Yes

User avatar
adafruit_support_carter
 
Posts: 29168
Joined: Tue Nov 29, 2016 2:45 pm

Re: Help with code. Adafruit Trinket MO

Post by adafruit_support_carter »

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?

Locked
Please be positive and constructive with your questions and comments.

Return to “Trinket ATTiny, Trinket M0”