import RPi.GPIO as GPIO
from time import sleep

def onoff(period, pin):
    """Symmetric square wave, equal time on/off"""
    half_cycle = period / 2.0
    GPIO.output(pin, GPIO.HIGH)
    sleep(half_cycle)
    GPIO.output(pin, GPIO.LOW)
    sleep(half_cycle)

def strobe(freq, dur, pin):
    nflashes = freq * dur
    seconds_to_sleep = 1.0 / freq

    # Use Raspberry-Pi board pin numbers. In other words, 11 means pin
    # number 11, not GPIO 11.
    GPIO.setmode(GPIO.BOARD) 

    GPIO.setup(pin, GPIO.OUT) # requires root?
    for i in range(nflashes):
        onoff(seconds_to_sleep, pin)
    GPIO.cleanup()


import RPi.GPIO as GPIO
from time import sleep

def onoff(ontime, offtime, pin):
    GPIO.output(pin, GPIO.HIGH)
    sleep(ontime)
    GPIO.output(pin, GPIO.LOW)
    sleep(offtime)

def strobe(freq, dur, pin):
    nflashes = freq * dur
    period = 1.0 / freq

    # Use Raspberry-Pi board pin numbers. In other words, 11 means pin
    # number 11, not GPIO 11.
    GPIO.setmode(GPIO.BOARD) 

    GPIO.setup(pin, GPIO.OUT) # requires root?
    for i in range(nflashes):
        onoff(period/2.0, period/2.0, pin)
    GPIO.cleanup()

Make onoff function more versatile
Make onoff function more versatile

+ 
  import RPi.GPIO as GPIO
  from time import sleep
  
+ def onoff(ontime, offtime, pin):
- def onoff(period, pin):
-     """Symmetric square wave, equal time on/off"""
-     half_cycle = period / 2.0
      GPIO.output(pin, GPIO.HIGH)
-     sleep(half_cycle)
+     sleep(ontime)
      GPIO.output(pin, GPIO.LOW)
-     sleep(half_cycle)
+     sleep(offtime)
  
  def strobe(freq, dur, pin):
      nflashes = freq * dur
-     seconds_to_sleep = 1.0 / freq
+     period = 1.0 / freq
  
      # Use Raspberry-Pi board pin numbers. In other words, 11 means pin
      # number 11, not GPIO 11.
      GPIO.setmode(GPIO.BOARD) 
  
      GPIO.setup(pin, GPIO.OUT) # requires root?
      for i in range(nflashes):
-         onoff(seconds_to_sleep, pin)
+         onoff(period/2.0, period/2.0, pin)
      GPIO.cleanup()
  
Make onoff function more versatile
## Code Before:
import RPi.GPIO as GPIO
from time import sleep

def onoff(period, pin):
    """Symmetric square wave, equal time on/off"""
    half_cycle = period / 2.0
    GPIO.output(pin, GPIO.HIGH)
    sleep(half_cycle)
    GPIO.output(pin, GPIO.LOW)
    sleep(half_cycle)

def strobe(freq, dur, pin):
    nflashes = freq * dur
    seconds_to_sleep = 1.0 / freq

    # Use Raspberry-Pi board pin numbers. In other words, 11 means pin
    # number 11, not GPIO 11.
    GPIO.setmode(GPIO.BOARD) 

    GPIO.setup(pin, GPIO.OUT) # requires root?
    for i in range(nflashes):
        onoff(seconds_to_sleep, pin)
    GPIO.cleanup()

## Instruction:
Make onoff function more versatile
## Code After:

import RPi.GPIO as GPIO
from time import sleep

def onoff(ontime, offtime, pin):
    GPIO.output(pin, GPIO.HIGH)
    sleep(ontime)
    GPIO.output(pin, GPIO.LOW)
    sleep(offtime)

def strobe(freq, dur, pin):
    nflashes = freq * dur
    period = 1.0 / freq

    # Use Raspberry-Pi board pin numbers. In other words, 11 means pin
    # number 11, not GPIO 11.
    GPIO.setmode(GPIO.BOARD) 

    GPIO.setup(pin, GPIO.OUT) # requires root?
    for i in range(nflashes):
        onoff(period/2.0, period/2.0, pin)
    GPIO.cleanup()
