Skip to content

Commit 786e6c5

Browse files
committed
Correct line endings
1 parent a320b9f commit 786e6c5

9 files changed

Lines changed: 691 additions & 691 deletions

File tree

examples/audio/motor_song.py

Lines changed: 201 additions & 201 deletions
Large diffs are not rendered by default.

examples/audio/random_droid.py

Lines changed: 53 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,53 @@
1-
import time
2-
import random
3-
from inventorhatmini import InventorHATMini
4-
from ttastromech import TTAstromech
5-
6-
"""
7-
Make your Inventor HAT Mini sound like an Astromech Droid!
8-
9-
This example uses the ttastromech library, for more details see https://pypi.org/project/ttastromech/
10-
To install enter the following on the command line: pip install ttastromech
11-
12-
Press "User" to play a random word out of the speaker.
13-
"""
14-
15-
# Constants
16-
MIN_WORD_LENGTH = 3 # The smallest word size
17-
MAX_WORD_LENGTH = 10 # The largest word size
18-
WAIT_TIME = 0.25 # The time (in seconds) to wait after playing a word, before accepting user input again
19-
20-
# Create a new InventorHATMini and TTAstromech
21-
board = InventorHATMini(init_leds=False)
22-
droid = TTAstromech()
23-
24-
25-
# Generate the characters from `c1` to `c2`, inclusive.
26-
def char_range(c1, c2):
27-
for c in range(ord(c1), ord(c2) + 1):
28-
yield chr(c)
29-
30-
31-
# Generate a random word from the letters a to z.
32-
def random_string(word_length=5, no_repeat=True):
33-
chars = list(char_range("a", "z"))
34-
word = ""
35-
char_count = 0
36-
while char_count != word_length:
37-
char = chars[random.randint(0, 25)]
38-
if char in word and no_repeat:
39-
pass
40-
else:
41-
word += char
42-
char_count += 1
43-
print("Saying:", word)
44-
return word
45-
46-
47-
# Loop forever
48-
while True:
49-
if board.switch_pressed():
50-
# Speak a random word when "User" is pressed
51-
word_length = random.randint(MIN_WORD_LENGTH, MAX_WORD_LENGTH)
52-
droid.speak(random_string(word_length, no_repeat=False))
53-
time.sleep(WAIT_TIME)
1+
import time
2+
import random
3+
from inventorhatmini import InventorHATMini
4+
from ttastromech import TTAstromech
5+
6+
"""
7+
Make your Inventor HAT Mini sound like an Astromech Droid!
8+
9+
This example uses the ttastromech library, for more details see https://pypi.org/project/ttastromech/
10+
To install enter the following on the command line: pip install ttastromech
11+
12+
Press "User" to play a random word out of the speaker.
13+
"""
14+
15+
# Constants
16+
MIN_WORD_LENGTH = 3 # The smallest word size
17+
MAX_WORD_LENGTH = 10 # The largest word size
18+
WAIT_TIME = 0.25 # The time (in seconds) to wait after playing a word, before accepting user input again
19+
20+
# Create a new InventorHATMini and TTAstromech
21+
board = InventorHATMini(init_leds=False)
22+
droid = TTAstromech()
23+
24+
25+
# Generate the characters from `c1` to `c2`, inclusive.
26+
def char_range(c1, c2):
27+
for c in range(ord(c1), ord(c2) + 1):
28+
yield chr(c)
29+
30+
31+
# Generate a random word from the letters a to z.
32+
def random_string(word_length=5, no_repeat=True):
33+
chars = list(char_range("a", "z"))
34+
word = ""
35+
char_count = 0
36+
while char_count != word_length:
37+
char = chars[random.randint(0, 25)]
38+
if char in word and no_repeat:
39+
pass
40+
else:
41+
word += char
42+
char_count += 1
43+
print("Saying:", word)
44+
return word
45+
46+
47+
# Loop forever
48+
while True:
49+
if board.switch_pressed():
50+
# Speak a random word when "User" is pressed
51+
word_length = random.randint(MIN_WORD_LENGTH, MAX_WORD_LENGTH)
52+
droid.speak(random_string(word_length, no_repeat=False))
53+
time.sleep(WAIT_TIME)

examples/extras/gpio_encoder.py

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
1-
import time
2-
from inventorhatmini import InventorHATMini, GPIO_1, GPIO_2
3-
# from ioexpander.common import REVERSED_DIR
4-
5-
"""
6-
An example of how to read a rotary encoder connected to Inventor HAT Mini's GPIO pins.
7-
8-
Press "User" to exit the program.
9-
"""
10-
11-
# Constants
12-
CHANNEL = 3 # The encoder channel to use (1 and 2 are used by Inventor's motor connectors)
13-
14-
# Create a new InventorHATMini
15-
board = InventorHATMini(init_leds=False)
16-
17-
# Create an Encoder object using two GPIO pins
18-
enc = board.encoder_from_gpio_pins(CHANNEL, GPIO_1, GPIO_2)
19-
20-
# Uncomment the below line (and the top imports) to
21-
# reverse the counting direction of the encoder
22-
# enc.direction(REVERSED_DIR)
23-
24-
# Read the encoder until the user button is pressed
25-
while not board.switch_pressed():
26-
27-
# Print out the current step and turn of the rotary encoder
28-
print("Step = ", enc.step(), ", Turn = ", enc.turn(), sep="")
29-
30-
time.sleep(0.1)
1+
import time
2+
from inventorhatmini import InventorHATMini, GPIO_1, GPIO_2
3+
# from ioexpander.common import REVERSED_DIR
4+
5+
"""
6+
An example of how to read a rotary encoder connected to Inventor HAT Mini's GPIO pins.
7+
8+
Press "User" to exit the program.
9+
"""
10+
11+
# Constants
12+
CHANNEL = 3 # The encoder channel to use (1 and 2 are used by Inventor's motor connectors)
13+
14+
# Create a new InventorHATMini
15+
board = InventorHATMini(init_leds=False)
16+
17+
# Create an Encoder object using two GPIO pins
18+
enc = board.encoder_from_gpio_pins(CHANNEL, GPIO_1, GPIO_2)
19+
20+
# Uncomment the below line (and the top imports) to
21+
# reverse the counting direction of the encoder
22+
# enc.direction(REVERSED_DIR)
23+
24+
# Read the encoder until the user button is pressed
25+
while not board.switch_pressed():
26+
27+
# Print out the current step and turn of the rotary encoder
28+
print("Step = ", enc.step(), ", Turn = ", enc.turn(), sep="")
29+
30+
time.sleep(0.1)

examples/extras/read_servo_pins.py

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,44 @@
1-
import time
2-
from inventorhatmini import InventorHATMini, NUM_SERVOS, LED_SERVO_1
3-
from ioexpander import IN # or IN_PU of a pull-up is wanted
4-
5-
"""
6-
Shows how to initialise and use Inventor HAT Mini's servo headers as 3.3V inputs and read them.
7-
8-
Press "User" to exit the program.
9-
"""
10-
11-
# Constants
12-
BRIGHTNESS = 0.4 # The brightness of the LEDs
13-
SERVO_NAMES = ("S0", "S1", "S2", "S3") # Friendly names to give the GPIOs
14-
USE_LEDS = True # Whether to use the LEDs to show GPIO state (requires code to run with sudo)
15-
16-
# Create a new InventorHATMini
17-
board = InventorHATMini(init_servos=False, init_leds=USE_LEDS)
18-
19-
# Setup each servo as an input
20-
for i in range(NUM_SERVOS):
21-
board.servo_pin_mode(i, IN) # or IN_PU of a pull-up is wanted
22-
23-
# Read the servos until the user button is pressed
24-
while not board.switch_pressed():
25-
26-
# Read each servo in turn and print its value
27-
for i in range(NUM_SERVOS):
28-
value = board.servo_pin_value(i)
29-
print(SERVO_NAMES[i], " = ", value, sep="", end=", ")
30-
31-
# Set the neighbouring LED to a colour based on
32-
# the input, with Green for high and Blue for low
33-
if value:
34-
board.leds.set_hsv(i + LED_SERVO_1, 0.333, 1.0, BRIGHTNESS)
35-
else:
36-
board.leds.set_hsv(i + LED_SERVO_1, 0.666, 1.0, BRIGHTNESS)
37-
38-
# Print a new line
39-
print()
40-
41-
time.sleep(0.1)
42-
43-
# Turn off the LED bars
44-
board.leds.clear()
1+
import time
2+
from inventorhatmini import InventorHATMini, NUM_SERVOS, LED_SERVO_1
3+
from ioexpander import IN # or IN_PU of a pull-up is wanted
4+
5+
"""
6+
Shows how to initialise and use Inventor HAT Mini's servo headers as 3.3V inputs and read them.
7+
8+
Press "User" to exit the program.
9+
"""
10+
11+
# Constants
12+
BRIGHTNESS = 0.4 # The brightness of the LEDs
13+
SERVO_NAMES = ("S0", "S1", "S2", "S3") # Friendly names to give the GPIOs
14+
USE_LEDS = True # Whether to use the LEDs to show GPIO state (requires code to run with sudo)
15+
16+
# Create a new InventorHATMini
17+
board = InventorHATMini(init_servos=False, init_leds=USE_LEDS)
18+
19+
# Setup each servo as an input
20+
for i in range(NUM_SERVOS):
21+
board.servo_pin_mode(i, IN) # or IN_PU of a pull-up is wanted
22+
23+
# Read the servos until the user button is pressed
24+
while not board.switch_pressed():
25+
26+
# Read each servo in turn and print its value
27+
for i in range(NUM_SERVOS):
28+
value = board.servo_pin_value(i)
29+
print(SERVO_NAMES[i], " = ", value, sep="", end=", ")
30+
31+
# Set the neighbouring LED to a colour based on
32+
# the input, with Green for high and Blue for low
33+
if value:
34+
board.leds.set_hsv(i + LED_SERVO_1, 0.333, 1.0, BRIGHTNESS)
35+
else:
36+
board.leds.set_hsv(i + LED_SERVO_1, 0.666, 1.0, BRIGHTNESS)
37+
38+
# Print a new line
39+
print()
40+
41+
time.sleep(0.1)
42+
43+
# Turn off the LED bars
44+
board.leds.clear()

0 commit comments

Comments
 (0)