Skip to content

Commit

Permalink
Updating examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Wer-Wolf committed Sep 2, 2020
1 parent d8e17f4 commit 5eef972
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions examples/checkPwm.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
# (docs.onion.io/omega2-docs/generating-pwm-signals.html -> Enabling PWM Pins)

with pwm.OnionPwm(channel=0) as led: # Initialize PWM channel 0 (GPIO 18)
led.setFrequency(1000) # Set the Frequency of PWM channel 0 to 1000 Hz
led.setDutyCycle(0) # Set the duty cycle of PWM channel 0 to 0%
led.set_frequency(1000) # Set the Frequency of PWM channel 0 to 1000 Hz
led.set_duty_cycle(0) # Set the duty cycle of PWM channel 0 to 0%
led.enable() # Enables PWM channel 0 --> LED stays off
try:
while 1:
newCycle = input('Enter duty cycle (0 - 100) or EXIT: ')
if newCycle == 'EXIT':
break
else:
led.setDutyCycle(float(newCycle)) # Changes the duty cycle of PWM channel 0
print('Current duty cycle: %3.10f' % led.getDutyCycle())
led.set_duty_cycle(float(newCycle)) # Changes the duty cycle of PWM channel 0
print('Current duty cycle: %3.10f' % led.get_duty_cycle())
print('As you can see, there might be some slight difference due to rounding')
finally:
led.disable()
6 changes: 3 additions & 3 deletions examples/led.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
# Dont forget enabling the pwm0 pin!
# (docs.onion.io/omega2-docs/generating-pwm-signals.html -> Enabling PWM Pins)
with pwm.OnionPwm(channel=0) as led: # Initialize PWM channel 0 (GPIO 18)
led.setFrequency(1000) # Set the Frequency of PWM channel 0 to 1000 Hz
led.setDutyCycle(50) # Set the duty cycle of PWM channel 0 to 50%
led.set_frequency(1000) # Set the Frequency of PWM channel 0 to 1000 Hz
led.set_duty_cycle(50) # Set the duty cycle of PWM channel 0 to 50%
led.enable() # Enables PWM channel 0 --> LED turns on
print('Wait 5 seconds, look at the LED')
time.sleep(5)

led.setDutyCycle(100) # Set the duty cycle of PWM channel 0 to 100%
led.set_duty_cycle(100) # Set the duty cycle of PWM channel 0 to 100%
print('Wait 5 seconds, look at the LED again')
time.sleep(5)

Expand Down

0 comments on commit 5eef972

Please sign in to comment.