Python Forum
Setting GPIO on Raspberry PI using a function
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Setting GPIO on Raspberry PI using a function
#2
This is unrelated to your code, but all those functions look veeeeery similar to me, so I'd probably just turn them all into a single function.  Maybe something like:
def set_pins(first=True, second=True, third=True):
  GPIO.output(17, GPIO.HIGH if first else GPIO.LOW)
  GPIO.output(27, GPIO.HIGH if second else GPIO.LOW)
  GPIO.output(22, GPIO.HIGH if third else GPIO.LOW)
Then, maybe I'd have some helper functions for each combination:
MUX1shift1_Y0 = lambda: set_pins(False, False, False)
# etc
The helpers could probably all be generated in a loop, instead of copy-paste (but I'm a little too busy to think that hard right now, lol).

As to your actual question, what does this mean?
Quote: I need the GPIO's to be returned from the function
Given one of the combinations, what, exactly, should be the return value?
Reply


Messages In This Thread
RE: Setting GPIO on Raspberry PI using a function - by nilamo - Dec-28-2017, 10:26 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  function return boolean based on GPIO pin reading caslor 2 1,236 Feb-04-2023, 12:30 PM
Last Post: caslor
  class Update input (Gpio pin raspberry pi) caslor 2 851 Jan-30-2023, 08:05 PM
Last Post: caslor
  Webhook, post_data, GPIO partial changes DigitalID 2 1,043 Nov-10-2022, 09:50 PM
Last Post: deanhystad
  try function working on PC but not raspberry pi AnotherSam 1 1,573 Oct-11-2021, 04:51 AM
Last Post: bowlofred
  Seemingly unstable GPIO output while executing from RetroPie LouF 6 4,009 Feb-19-2021, 06:29 AM
Last Post: LouF
  Picture changing triggered by GPIO q_nerk 2 2,625 Dec-14-2020, 03:32 PM
Last Post: DeaD_EyE
  GPIO high if network IP has good ping duckredbeard 3 2,400 Oct-12-2020, 10:41 PM
Last Post: bowlofred
  raspberry pi tank gpio help jatgm1 1 2,453 May-06-2020, 09:00 PM
Last Post: Larz60+
  Where should I place GPIO.cleanup() shallanq 2 2,216 Apr-11-2020, 05:02 AM
Last Post: shallanq
  Orange PI Win steering LEDs connect to GPIO djmcg 0 1,564 Dec-27-2019, 08:26 AM
Last Post: djmcg

Forum Jump:

User Panel Messages

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