From 862806f357cd35dca7b00fc10e977699fba70bf7 Mon Sep 17 00:00:00 2001 From: ZodiusInfuser Date: Thu, 4 May 2023 14:10:12 +0100 Subject: [PATCH] Simplified example I2C setup --- .../examples/breakout_encoder_wheel/buttons.py | 6 ++---- .../examples/breakout_encoder_wheel/chase_game.py | 6 ++---- .../examples/breakout_encoder_wheel/clock.py | 9 ++++----- .../breakout_encoder_wheel/colour_picker.py | 7 ++----- .../examples/breakout_encoder_wheel/encoder.py | 3 ++- .../examples/breakout_encoder_wheel/gpio_pwm.py | 13 ++++++------- .../examples/breakout_encoder_wheel/led_rainbow.py | 7 ++----- .../examples/breakout_encoder_wheel/stop_watch.py | 8 +++----- 8 files changed, 23 insertions(+), 36 deletions(-) diff --git a/micropython/examples/breakout_encoder_wheel/buttons.py b/micropython/examples/breakout_encoder_wheel/buttons.py index 65d70d69..48a63c5f 100644 --- a/micropython/examples/breakout_encoder_wheel/buttons.py +++ b/micropython/examples/breakout_encoder_wheel/buttons.py @@ -1,4 +1,5 @@ from pimoroni_i2c import PimoroniI2C +from pimoroni import BREAKOUT_GARDEN_I2C_PINS # or PICO_EXPLORER_I2C_PINS or HEADER_I2C_PINS from breakout_encoder_wheel import BreakoutEncoderWheel, UP, DOWN, LEFT, RIGHT, CENTRE, NUM_BUTTONS, NUM_LEDS """ @@ -7,14 +8,11 @@ A demonstration of reading the 5 buttons on Encoder Wheel. Press Ctrl+C to stop the program. """ -PINS_BREAKOUT_GARDEN = {"sda": 4, "scl": 5} -PINS_PICO_EXPLORER = {"sda": 20, "scl": 21} - # Constants BUTTON_NAMES = ["Up", "Down", "Left", "Right", "Centre"] # Create a new BreakoutEncoderWheel -i2c = PimoroniI2C(**PINS_BREAKOUT_GARDEN) +i2c = PimoroniI2C(**BREAKOUT_GARDEN_I2C_PINS) wheel = BreakoutEncoderWheel(i2c) # Variables diff --git a/micropython/examples/breakout_encoder_wheel/chase_game.py b/micropython/examples/breakout_encoder_wheel/chase_game.py index e621c9b7..9c0bf839 100644 --- a/micropython/examples/breakout_encoder_wheel/chase_game.py +++ b/micropython/examples/breakout_encoder_wheel/chase_game.py @@ -1,5 +1,6 @@ import random from pimoroni_i2c import PimoroniI2C +from pimoroni import BREAKOUT_GARDEN_I2C_PINS # or PICO_EXPLORER_I2C_PINS or HEADER_I2C_PINS from breakout_encoder_wheel import BreakoutEncoderWheel, NUM_LEDS """ @@ -10,10 +11,7 @@ When you reach the goal, the goal will move to a new random position. Press Ctrl+C to stop the program. """ -PINS_BREAKOUT_GARDEN = {"sda": 4, "scl": 5} -PINS_PICO_EXPLORER = {"sda": 20, "scl": 21} - -i2c = PimoroniI2C(**PINS_BREAKOUT_GARDEN) +i2c = PimoroniI2C(**BREAKOUT_GARDEN_I2C_PINS) wheel = BreakoutEncoderWheel(i2c) # The band colour hues to show in Angle mode diff --git a/micropython/examples/breakout_encoder_wheel/clock.py b/micropython/examples/breakout_encoder_wheel/clock.py index 6016763a..547fbac2 100644 --- a/micropython/examples/breakout_encoder_wheel/clock.py +++ b/micropython/examples/breakout_encoder_wheel/clock.py @@ -1,7 +1,7 @@ import time from machine import RTC - from pimoroni_i2c import PimoroniI2C +from pimoroni import BREAKOUT_GARDEN_I2C_PINS # or PICO_EXPLORER_I2C_PINS or HEADER_I2C_PINS from breakout_encoder_wheel import BreakoutEncoderWheel, NUM_LEDS """ @@ -10,9 +10,6 @@ Displays a 12 hour clock on Encoder Wheel's LED ring, getting time from the syst Press Ctrl+C to stop the program. """ -PINS_BREAKOUT_GARDEN = {"sda": 4, "scl": 5} -PINS_PICO_EXPLORER = {"sda": 20, "scl": 21} - # Datetime Indices HOUR = 4 MINUTE = 5 @@ -30,8 +27,10 @@ MILLIS_PER_HOUR = MILLIS_PER_MINUTE * 60 MILLIS_PER_HALF_DAY = MILLIS_PER_HOUR * 12 # Create a new BreakoutEncoderWheel -i2c = PimoroniI2C(**PINS_BREAKOUT_GARDEN) +i2c = PimoroniI2C(**BREAKOUT_GARDEN_I2C_PINS) wheel = BreakoutEncoderWheel(i2c) + +# Access the built-in RTC rtc = RTC() diff --git a/micropython/examples/breakout_encoder_wheel/colour_picker.py b/micropython/examples/breakout_encoder_wheel/colour_picker.py index dcaef39a..c6e11cf3 100644 --- a/micropython/examples/breakout_encoder_wheel/colour_picker.py +++ b/micropython/examples/breakout_encoder_wheel/colour_picker.py @@ -1,6 +1,6 @@ import time - from pimoroni_i2c import PimoroniI2C +from pimoroni import BREAKOUT_GARDEN_I2C_PINS # or PICO_EXPLORER_I2C_PINS or HEADER_I2C_PINS from breakout_encoder_wheel import BreakoutEncoderWheel, UP, DOWN, LEFT, RIGHT, CENTRE, NUM_LEDS """ @@ -16,9 +16,6 @@ Press the centre to hide the selection marker Press Ctrl+C to stop the program. """ -PINS_BREAKOUT_GARDEN = {"sda": 4, "scl": 5} -PINS_PICO_EXPLORER = {"sda": 20, "scl": 21} - # Constants BRIGHTNESS_STEP = 0.02 # How much to increase or decrease the brightness each update SATURATION_STEP = 0.02 # How much to increase or decrease the saturation each update @@ -26,7 +23,7 @@ UPDATES = 50 # How many times to update the LEDs per second UPDATE_RATE_US = 1000000 // UPDATES # Create a new BreakoutEncoderWheel -i2c = PimoroniI2C(**PINS_BREAKOUT_GARDEN) +i2c = PimoroniI2C(**BREAKOUT_GARDEN_I2C_PINS) wheel = BreakoutEncoderWheel(i2c) # Variables diff --git a/micropython/examples/breakout_encoder_wheel/encoder.py b/micropython/examples/breakout_encoder_wheel/encoder.py index 699f9e8e..b35b59ab 100644 --- a/micropython/examples/breakout_encoder_wheel/encoder.py +++ b/micropython/examples/breakout_encoder_wheel/encoder.py @@ -1,4 +1,5 @@ from pimoroni_i2c import PimoroniI2C +from pimoroni import BREAKOUT_GARDEN_I2C_PINS # or PICO_EXPLORER_I2C_PINS or HEADER_I2C_PINS from breakout_encoder_wheel import BreakoutEncoderWheel """ @@ -11,7 +12,7 @@ PINS_BREAKOUT_GARDEN = {"sda": 4, "scl": 5} PINS_PICO_EXPLORER = {"sda": 20, "scl": 21} # Create a new BreakoutEncoderWheel -i2c = PimoroniI2C(**PINS_BREAKOUT_GARDEN) +i2c = PimoroniI2C(**BREAKOUT_GARDEN_I2C_PINS) wheel = BreakoutEncoderWheel(i2c) # Variables diff --git a/micropython/examples/breakout_encoder_wheel/gpio_pwm.py b/micropython/examples/breakout_encoder_wheel/gpio_pwm.py index c7904f5f..832fd1c3 100644 --- a/micropython/examples/breakout_encoder_wheel/gpio_pwm.py +++ b/micropython/examples/breakout_encoder_wheel/gpio_pwm.py @@ -1,9 +1,9 @@ import math import time - -from breakout_ioexpander import BreakoutIOExpander from pimoroni_i2c import PimoroniI2C +from pimoroni import BREAKOUT_GARDEN_I2C_PINS # or PICO_EXPLORER_I2C_PINS or HEADER_I2C_PINS from breakout_encoder_wheel import BreakoutEncoderWheel, CENTRE, GPIOS, NUM_GPIOS +from breakout_ioexpander import PWM """ Output a sine wave PWM sequence on the Encoder Wheel's side GPIO pins. @@ -11,16 +11,14 @@ Output a sine wave PWM sequence on the Encoder Wheel's side GPIO pins. Press the centre button or Ctrl+C to stop the program. """ -PINS_BREAKOUT_GARDEN = {"sda": 4, "scl": 5} -PINS_PICO_EXPLORER = {"sda": 20, "scl": 21} - +# Constants SPEED = 5 # The speed that the PWM will cycle at UPDATES = 50 # How many times to update LEDs and Servos per second UPDATE_RATE_US = 1000000 // UPDATES FREQUENCY = 1000 # The frequency to run the PWM at # Create a new BreakoutEncoderWheel -i2c = PimoroniI2C(**PINS_BREAKOUT_GARDEN) +i2c = PimoroniI2C(**BREAKOUT_GARDEN_I2C_PINS) wheel = BreakoutEncoderWheel(i2c) # Set the PWM frequency for the GPIOs @@ -28,8 +26,9 @@ period = wheel.gpio_pwm_frequency(FREQUENCY) # Set the GPIO pins to PWM outputs for g in GPIOS: - wheel.gpio_pin_mode(g, BreakoutIOExpander.PIN_PWM) + wheel.gpio_pin_mode(g, PWM) +# Variables offset = 0.0 diff --git a/micropython/examples/breakout_encoder_wheel/led_rainbow.py b/micropython/examples/breakout_encoder_wheel/led_rainbow.py index 8010c10c..d6ceea69 100644 --- a/micropython/examples/breakout_encoder_wheel/led_rainbow.py +++ b/micropython/examples/breakout_encoder_wheel/led_rainbow.py @@ -1,6 +1,6 @@ import time - from pimoroni_i2c import PimoroniI2C +from pimoroni import BREAKOUT_GARDEN_I2C_PINS # or PICO_EXPLORER_I2C_PINS or HEADER_I2C_PINS from breakout_encoder_wheel import BreakoutEncoderWheel, NUM_LEDS """ @@ -9,9 +9,6 @@ Displays a rotating rainbow pattern on Encoder Wheel's LED ring. Press Ctrl+C to stop the program. """ -PINS_BREAKOUT_GARDEN = {"sda": 4, "scl": 5} -PINS_PICO_EXPLORER = {"sda": 20, "scl": 21} - # Constants SPEED = 5 # The speed that the LEDs will cycle at BRIGHTNESS = 1.0 # The brightness of the LEDs @@ -19,7 +16,7 @@ UPDATES = 50 # How many times the LEDs will be updated per second UPDATE_RATE_US = 1000000 // UPDATES # Create a new BreakoutEncoderWheel -i2c = PimoroniI2C(**PINS_BREAKOUT_GARDEN) +i2c = PimoroniI2C(**BREAKOUT_GARDEN_I2C_PINS) wheel = BreakoutEncoderWheel(i2c) # Variables diff --git a/micropython/examples/breakout_encoder_wheel/stop_watch.py b/micropython/examples/breakout_encoder_wheel/stop_watch.py index 3581c91e..19e47356 100644 --- a/micropython/examples/breakout_encoder_wheel/stop_watch.py +++ b/micropython/examples/breakout_encoder_wheel/stop_watch.py @@ -1,7 +1,7 @@ import math import time - from pimoroni_i2c import PimoroniI2C +from pimoroni import BREAKOUT_GARDEN_I2C_PINS # or PICO_EXPLORER_I2C_PINS or HEADER_I2C_PINS from breakout_encoder_wheel import BreakoutEncoderWheel, CENTRE, NUM_LEDS """ @@ -12,9 +12,6 @@ Press the centre button to start the stopwatch, then again to pause and resume. Press Ctrl+C to stop the program. """ -PINS_BREAKOUT_GARDEN = {"sda": 4, "scl": 5} -PINS_PICO_EXPLORER = {"sda": 20, "scl": 21} - # Constants BRIGHTNESS = 1.0 # The brightness of the LEDs when the stopwatch is running UPDATES = 50 # How many times the LEDs will be updated per second @@ -29,7 +26,8 @@ UPDATES_PER_PULSE = IDLE_PULSE_TIME * UPDATES IDLE, COUNTING, PAUSED = range(3) # The state constants used for program flow -i2c = PimoroniI2C(**PINS_BREAKOUT_GARDEN) +# Create a new BreakoutEncoderWheel +i2c = PimoroniI2C(**BREAKOUT_GARDEN_I2C_PINS) wheel = BreakoutEncoderWheel(i2c) # Variables