-
Notifications
You must be signed in to change notification settings - Fork 497
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automation 2040w MicroPython PWM (#489)
Co-authored-by: ZodiusInfuser <[email protected]>
- Loading branch information
1 parent
8280a6a
commit 28b6698
Showing
9 changed files
with
355 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import time | ||
from automation import Automation2040W, SWITCH_A | ||
|
||
""" | ||
Demonstrates how to toggle each of Automation 2040 W's output terminals. | ||
Press "A" to exit the program. | ||
""" | ||
|
||
TIME_PER_TOGGLE = 0.5 # How much time to wait between each toggle (in seconds) | ||
OUTPUT_NAMES = ("O1", "O2", "O3") # The friendly names to give each digital output | ||
|
||
# Create a new Automation2040W | ||
board = Automation2040W() | ||
|
||
# Enable the LED of the switch used to exit the loop | ||
board.switch_led(SWITCH_A, 50) # Half Brightness | ||
|
||
toggle = True | ||
index = 0 | ||
|
||
# Toggle the outputs until the user switch is pressed | ||
while not board.switch_pressed(SWITCH_A): | ||
|
||
# Toggle an output | ||
for output_percentage in range(101): | ||
|
||
if toggle is True: | ||
board.output(index, output_percentage) | ||
else: | ||
board.output(index, 100.0 - output_percentage) | ||
|
||
# Print the state of all outputs | ||
for i in range(board.NUM_OUTPUTS): | ||
print(OUTPUT_NAMES[i], " = ", board.output_percent(i), sep="", end=", ") | ||
|
||
# Print a new line | ||
print() | ||
time.sleep(0.01) | ||
|
||
index += 1 # Move on to the next output | ||
if index >= board.NUM_OUTPUTS: | ||
index = 0 # Go back to the first output | ||
toggle = not toggle # Invert the toggle value | ||
|
||
time.sleep(TIME_PER_TOGGLE) | ||
|
||
# Put the board back into a safe state | ||
board.reset() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.