コード例 #1
0
 def clear_clock(self):
     """
     Clears the clock display.  Otherwise it stays on, even after the program runs
     """
     # Use I2C connection for clock display
     i2c = board.I2C()
     # Create a new display which clears the current display
     self.display = Seg7x4(i2c)
コード例 #2
0
    def load_config(self, config_input):
        # Check for parseable YAML
        try:
            self.config = yaml.load(config_input)
        except:
            print("Could not parse provided configuration")
            return 1

        # Is the configuration valid?
        # Probably should do some config validation here, but......

        # Collapse down to just the Launch Director part. This allows 'Launchdirector' to be a sub-part of a larger config.
        self.config = self.config['launchdirector']

        # Check if output units is set. If not, default to Metric.
        if 'output_units' not in self.config:
            print("No output units found. Defaulting to metric.")
            self.config['output_units'] = 'metric'
        elif self.config['output_units'].lower() not in ('metric', 'imperial'):
            print("Invalid unit option found. Defaulting to metric.")
            self.config['output_units'] = 'metric'

        # If any displays are defined, set them up.
        if self.config['displays']:
            for disp_name in self.config['displays']:
                # Set up i2c communication
                if self.config['displays'][disp_name]['size'] == '1':
                    self.displays[disp_name] = BigSeg7x4(
                        self.i2c,
                        address=self.config['displays'][disp_name]['id'])
                else:
                    self.displays[disp_name] = Seg7x4(
                        self.i2c,
                        address=self.config['displays'][disp_name]['id'])
                # Set initial values based on name
                if disp_name == 'met':
                    self.displays[disp_name].print("00:00")
                elif disp_name in ('vel', 'alt'):
                    self.displays[disp_name].print("0.000")
        # If audio devices are defined, set them up.
        #if self.config['audio']:
        #	# Currently only 'sonos' is understood. Maybe some day another tyep will be understood too.
        #	if self.config['audio']['type'] == 'sonos':
        #		import soco
        #		self.audiodev = soco(self.config['audio']['host'])
        #		print("Connected to Sonos device: " + self.audiodev.player_name)

        return 0
コード例 #3
0
    def __init__(self,
                 timezone="Pacific",
                 hour_24=False,
                 auto_dst=True,
                 sound=False,
                 brightness=1.0,
                 debug=False):
        # Input parameters
        self._timezone = timezone
        self._hour_24_12 = hour_24
        self._dst = False
        self._auto_dst = auto_dst
        self._sound = sound
        self._colon = True
        self._message = "    "
        self._brightness = brightness

        self._param_list = [("1-12", 1, 12), ("1-31", 1, 31),
                            ("20--", 2010, 2037), ("0-23", 0, 23),
                            ("0-59", 0, 59), ("", 0, 1), ("", 1, 10),
                            ("----", 0, 0)]

        # Holder for parameter values
        self._param_val_list = [
            0, 0, 0, 0, 0, self._sound,
            int(self._brightness * 10)
        ]

        # Rotary encoder
        self._sel_sw = DigitalInOut(board.D9)
        self._sel_sw.direction = Direction.INPUT
        self._sel_sw.pull = Pull.UP
        self._enc = enc.IncrementalEncoder(board.D5, board.D6)
        # Piezo speaker
        self._piezo = board.D13  # Shared with L13 LED
        # Display
        i2c = board.I2C()
        self._display = Seg7x4(i2c, address=0x70)
        self._display.brightness = brightness
        self._display.fill(0)  # Clear the display
        self._display.print("----")

        # Debug parameters
        self._debug = debug
        if self._debug:
            print("*Init:", self.__class__)
            print("*Init: ", self.__dict__)
コード例 #4
0
sudo apt-get update
sudo apt-get install git build-essential python-dev python-smbus
git clone https://github.com/adafruit/Adafruit_Python_BMP.git
cd Adafruit_Python_BMP
sudo python setup.py install

pip3 install adafruit-circuitpython-ht16k33
'''
import time
import board
import adafruit_dht
import Adafruit_BMP.BMP085 as BMP085
from adafruit_ht16k33.segments import Seg7x4
 
i2c = board.I2C()
display = Seg7x4(i2c)
display.brightness = 0.5
display.blink_rate = 3

def display():
    '''
    to print text to the display, you just use the print function. For the 7-segment display, 
    valid characters are 0-9, letters A-F, a period, and a hyphen. So if we want to print ABCD,
     we would use the following:
    '''    

    display.print(1234)
    display.print("ABCD")

    display[0] = '1'
    display[1] = '2'
red_led = DigitalInOut(board.RED_LED)
red_led.direction = Direction.OUTPUT
red_led.value = True

blue_led = DigitalInOut(board.BLUE_LED)
blue_led.direction = Direction.OUTPUT
blue_led.value = False

# target heart rate for interval training
# Change this number depending on your max heart rate, usually figured
# as (220 - your age).
max_rate = 180

# Seven Segment FeatherWing setup
i2c = board.I2C()
display_A = Seg7x4(i2c, address=0x70)  # this will be the BPM display
display_A.brightness = 15
display_A.fill(0)  # Clear the display
# Second display has A0 address jumpered
display_B = Seg7x4(i2c, address=0x71)  # this will be the % target display
display_B.brightness = 15
display_B.fill(0)  # Clear the display

# display_A "b.P.M."
display_A.set_digit_raw(0, 0b11111100)
display_A.set_digit_raw(1, 0b11110011)
display_A.set_digit_raw(2, 0b00110011)
display_A.set_digit_raw(3, 0b10100111)
# display_B "Prct"
display_B.set_digit_raw(0, 0b01110011)
display_B.set_digit_raw(1, 0b01010000)
コード例 #6
0
class ht16k33_clock:
    """
    Object for interacting with ht16k33 board controlled 7x4 clock display
    """
    # setup clock display
    # variables are the same for every instance setup, so not inside __init__
    display = Seg7x4(board.I2C())
    display.brightness = 0.4
    # setup display variables
    time_display: Optional[str] = None

    def display_time(self, train_times: List[datetime.datetime], min_clock_display=0):
        """
        Finds the time difference between the first train and now, then displays it on the clock
        display
        """
        # set the countdown display time
        self.clock_countdown_time(train_times, min_clock_display)
        # If a time is not None, display
        if self.time_display is not None:
            self.display.print(self.time_display)
        # Else clear the clock
        else:
            self.clear_clock()

    def clock_countdown_time(self, train_times: List[datetime.datetime], min_clock_display: int):
        """
        Takes in the train departure times and finds the difference between the soonest departure and
        now. Aslo has a minimum difference varaible so that if it takes a certain amount of time to walk
        to station, to account for that and only display a countdown that is achievable to walk to.
        :train_times: list of train departure times
        :min_clock_display: the minimum difference to display in minutes
        :return: Either the display countdown time or None if there isn't one within 99 minutes, the
                display limit
        """
        # Retrieve current time to compare
        now = datetime.datetime.now()
        # Get the difference between the soonest train and now
        train_num = 0
        next_train = train_times[train_num] - now
        # get seconds for the display
        next_train_seconds = str(next_train.seconds % 60)
        # make sure it is 0 padded
        if len(next_train_seconds) == 1:
            next_train_seconds = f"0{next_train_seconds}"
        # get the minutes for the display
        next_train_minutes = next_train.seconds / 60
        # While the difference is less than the minimum, use the next train/bus
        while (next_train_minutes < min_clock_display) and train_num < len(train_times):
            train_num += 1
            next_train = train_times[train_num] - now
            next_train_minutes = next_train.seconds / 60
        next_train_minutes_str = str(int(next_train_minutes))
        # make sure it is 0 padded
        if len(next_train_minutes_str) == 1:
            next_train_minutes_str = f"0{next_train_minutes}"
        # If minutes are not a length of 3 (too large for display)
        if len(next_train_minutes_str) == 2 and (next_train_minutes) > min_clock_display:
            # Change the display time
            self.time_display = f"{next_train_minutes}:{next_train_seconds}"
        # Else time display is None
        else:
            self.time_display = None

    def clear_clock(self):
        """
        Clears the clock display.  Otherwise it stays on, even after the program runs
        """
        # Use I2C connection for clock display
        i2c = board.I2C()
        # Create a new display which clears the current display
        self.display = Seg7x4(i2c)
コード例 #7
0
ファイル: 7seg_test.py プロジェクト: chrisgilldc/brickmaster
import argparse, board, time, signal
from adafruit_ht16k33.segments import Seg7x4, BigSeg7x4

# Parse incoming arguments
parser = argparse.ArgumentParser()
parser.add_argument('-a',action='append',help='Addresses of displays to test',required=True)
addresses = parser.parse_args().a

# Set up Segment objects for all provided IDs.

i2c = board.I2C()

d=0
displays = list()
for display in addresses:
	displays.append(Seg7x4(i2c,address=int(display,16)))

# Register keyboard interrupt handler to clean-up.
def keyboardInterruptHandler(signal, frame):
	for disp in displays:
		disp.fill(0)
	exit(0)

signal.signal(signal.SIGINT, keyboardInterruptHandler)

# Iterate and display until interrupted.

i=0
while i <= 11:
	output = str(i) + str(i) + str(i) + str(i)
	for disp in displays: