Python Forum
Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
C++ to Python conversion
#12
You can greatly simplify your code:
import time

GPIO.setmode(GPIO.BCM)

pinlist = [2,3,4,17,27,22,10,9]

GPIO.setup(pinlist, GPIO.OUT)
GPIO.output(pinlist,GPIO.HIGH)

def main():
   port_sequence = {
       'Rounds': [2, 3, 4, 17, 27, 22, 10, 9],
       'Queens': [22, 4, 27, 10, 3, 17, 22, 9],
       'RQueens': [10, 27, 4, 2, 3, 17, 22, 9],
       'Titums': [2, 27, 3, 22, 4, 10, 17, 9]
   }

   SleepA = 0.2
   SleepB = 1

   def play_tune(name):
       print(name)
       for val in port_sequence[name]:
           GPIO.output(val, GPIO.LOW)
           time.sleep(SleepA);
           GPIO.output(val, GPIO.HIGH)
           time.sleep(SleepA);
       GPIO.cleanup()

   for name in ['Rounds','Queens','RQueens','Titums']:
       play_tune(name)
   count = 0

   while count < 2:
       random.choice(Tune)()
       count += 1

       if count > 2:
           break

main()
I am unable to test
Reply


Messages In This Thread
C++ to Python conversion - by Jellyboo - Mar-26-2017, 11:39 AM
RE: C++ to Python conversion - by sparkz_alot - Mar-26-2017, 12:52 PM
RE: C++ to Python conversion - by Jellyboo - Mar-26-2017, 01:32 PM
RE: C++ to Python conversion - by ichabod801 - Mar-26-2017, 01:34 PM
RE: C++ to Python conversion - by sparkz_alot - Mar-26-2017, 03:30 PM
RE: C++ to Python conversion - by Larz60+ - Mar-26-2017, 03:48 PM
RE: C++ to Python conversion - by Jellyboo - Mar-28-2017, 06:44 PM
RE: C++ to Python conversion - by Larz60+ - Mar-28-2017, 07:32 PM
RE: C++ to Python conversion - by sparkz_alot - Mar-29-2017, 01:18 PM
RE: C++ to Python conversion - by Jellyboo - Mar-30-2017, 06:10 PM
RE: C++ to Python conversion - by Ofnuts - Mar-30-2017, 08:04 PM
RE: C++ to Python conversion - by Larz60+ - Mar-30-2017, 10:19 PM
RE: C++ to Python conversion - by Jellyboo - Mar-31-2017, 07:43 PM
RE: C++ to Python conversion - by Jellyboo - Apr-02-2017, 06:27 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  I need to add data types to cython conversion python to c Good_AI_User 1 1,058 Aug-19-2022, 07:52 AM
Last Post: Gribouillis
  Conversion of Oracle PL/SQL(packages, functions, procedures) to python modules. DivyaKumar 2 6,594 Jul-09-2020, 04:46 PM
Last Post: srikanth7482
  C to Python code conversion print problem anakk1n 1 2,226 May-22-2020, 04:15 PM
Last Post: deanhystad
  Python uppercase conversion conditions Jaypeng 7 3,064 Apr-29-2020, 11:24 AM
Last Post: jefsummers
  MATLAB to Python conversion stokd 10 5,131 Jan-19-2020, 09:14 PM
Last Post: stokd
  Excel Model Conversion into Python line7 2 2,309 Oct-09-2019, 07:51 AM
Last Post: line7
  python opencv grayscale conversion error Spandora 1 9,626 May-26-2019, 10:43 AM
Last Post: heiner55
  Vba conversion to Python stranger14u 1 3,633 May-26-2019, 08:01 AM
Last Post: heiner55
  Conversion of Time Duration in seconds in python jdevansh99 0 2,896 Jun-05-2018, 05:12 PM
Last Post: jdevansh99

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020