element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Code Exchange
  • Technologies
  • More
Code Exchange
Forum Python 3 code Question
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Code Exchange to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Suggested Answer
  • Replies 12 replies
  • Answers 3 answers
  • Subscribers 51 subscribers
  • Views 2608 views
  • Users 0 members are here
  • Code Exchange
Related

Python 3 code Question

ellip
ellip over 8 years ago

Hi.  I am new to the Raspberry Pi.  I have a Raspberry Pi 3 and a PiFace 2.  I am trying to update a Christmas decoration made over 40 years ago by my father. It was run by a rotisserie motor and a wooden cylinder with copper strips and screws to make contact and light the stars up in sequences.

 

I have 5 stars in the following formation:

 

     1          2

 

          5

 

     4          3

 

I am trying to have the stars light up in a certain sequence with a small delay in between each function

 

1

2

3

4

5

1,2,3

2,3,4

3,4,1

4,1,2

1,2,5

2,3,5

3,4,5

4,5,1

1,2,3,4,5

then begin the sequence again.

I have tried following as many of the posts as I can and receive errors on everything from syntax to int and tuples.

I am sure that it is something that is simple to the rest of you but just eludes me.  Any help in any way will be greatly appreciated.

Elli

  • Sign in to reply
  • Cancel

Top Replies

  • jdlui
    jdlui over 8 years ago +3 suggested
    Hi Ellen, Suggestion: With any problem I think it's helpful try and break things into pieces. Share more info with us on what you've tried, what isn't working, what code you are using. I.E. Have you tested…
  • mgillett
    mgillett over 7 years ago in reply to dougw +3
    I appreciated the two of you demonstrating two solutions to this problem. Further I appreciate seeing the first examples of going line by line through the code then the "better" coding style making the…
  • urkraft
    urkraft over 8 years ago in reply to urkraft +1 suggested
    To Douglas Wong: Sorry, i see now that your post was not directed to me. Was not very focused when i read it. I did notice that there was a very important bug in my code in that it did not handle interrupts…
Parents
  • urkraft
    0 urkraft over 8 years ago

    To Douglas Wong:

     

    Strange, the code resulted in the exact sequence specified. If you had bothered to test the code that i published you would have seen that it did actually produce the specified sequence - and with much less code than the gobeltygoop you posted to "correct" me!

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • urkraft
    0 urkraft over 8 years ago in reply to urkraft

    To Douglas Wong:

    Sorry, i see now that your post was not directed to me. Was not very focused when i read it. I did notice that there was a very important bug in my code in that it did not handle interrupts and could easily enter an undesirable state when stopped. A better solution to my submission follows:

     

    #!/usr/bin/env python3

    import pifacedigitalio, time, sys

     

    pfd = pifacedigitalio.PiFaceDigital()

     

    try:

         while True:

              pfd.output_port.value = 0x02

              time.sleep(0.5)

              pfd.output_port.value = 0x04

              time.sleep(0.5)

              pfd.output_port.value = 0x08

              time.sleep(0.5)

              pfd.output_port.value = 0x10

              time.sleep(0.5)

              pfd.output_port.value = 0x20

              time.sleep(0.5)

              pfd.output_port.value = 0x0E

              time.sleep(0.5)

              pfd.output_port.value = 0x1C

              time.sleep(0.5)

              pfd.output_port.value = 0x1A

              time.sleep(0.5)

              pfd.output_port.value = 0x16

              time.sleep(0.5)

              pfd.output_port.value = 0x26

              time.sleep(0.5)

              pfd.output_port.value = 0x2C

              time.sleep(0.5)

              pfd.output_port.value = 0x38

              time.sleep(0.5)

              pfd.output_port.value = 0x32

              time.sleep(0.5)

              pfd.output_port.value = 0x3E

              time.sleep(0.5)

    except:

         pfd.output_port.all_off()

         pfd.deinit_board()

         print('\nExiting due to unexpected interrupt.')

         sys.exit(0)

     

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • urkraft
    0 urkraft over 8 years ago in reply to urkraft

    Since there is a lot of unnecessary repetition and generally bad programming practices in my previous posts on this topic, i have cleaned up my code a bit. This is my alternative solution:

     

    #!/usr/bin/env python3

    import pifacedigitalio, time, sys

     

    pause_time = 0.5

    the_sequence = [0x02, 0x04, 0x08, 0x10, 0x20, 0x0E, 0x1C, 0x1A, 0x16, 0x26, 0x2C, 0x38, 0x32, 0x3E]

     

    pfd = pifacedigitalio.PiFaceDigital()

     

    try:

         while True:

              for seq in the_sequence:

                   pfd.output_port.value = seq

                   time.sleep(pause_time)

    except:

         pfd.output_port.all_off()

         pfd.deinit_board()

         print('\nExiting due to unexpected interrupt.')

         sys.exit(0)

     

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
Reply
  • urkraft
    0 urkraft over 8 years ago in reply to urkraft

    Since there is a lot of unnecessary repetition and generally bad programming practices in my previous posts on this topic, i have cleaned up my code a bit. This is my alternative solution:

     

    #!/usr/bin/env python3

    import pifacedigitalio, time, sys

     

    pause_time = 0.5

    the_sequence = [0x02, 0x04, 0x08, 0x10, 0x20, 0x0E, 0x1C, 0x1A, 0x16, 0x26, 0x2C, 0x38, 0x32, 0x3E]

     

    pfd = pifacedigitalio.PiFaceDigital()

     

    try:

         while True:

              for seq in the_sequence:

                   pfd.output_port.value = seq

                   time.sleep(pause_time)

    except:

         pfd.output_port.all_off()

         pfd.deinit_board()

         print('\nExiting due to unexpected interrupt.')

         sys.exit(0)

     

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube