示例#1
0
"""

import analogio
import board
from digitalio import DigitalInOut, Direction, Pull
import simpleio
import time

import neopixel

NLEDS = 10

color_sw = DigitalInOut(board.D7)
bright_sw = DigitalInOut(board.D8)
sat_sw = DigitalInOut(board.D9)
board_led = simpleio.DigitalOut(board.D13)
neos = neopixel.NeoPixel(board.D2, NLEDS)
neos.brightness = 0.1

DELAY = 0.3


class Option(object):
    def __init__(self, options, initial_index=None):
        if initial_index is None:
            initial_index = len(options) - 1
        self._options = options
        self._last_index = len(options) - 1
        self._index = initial_index
        self._inc = True
# reading from ds18x20 to obtain temperature
# then map a temp range to a color range and display
# color with neopixel
# Jon Proctor: added LED(13) Heartbeat
# and adding neopixel support

import time
import board
import simpleio
import neopixel

from adafruit_onewire.bus import OneWireBus
from adafruit_ds18x20 import DS18X20

heartbeat = simpleio.DigitalOut(board.D13)
heartbeat.value = True

# Initialize one-wire bus on board pin D5.
ow_bus = OneWireBus(board.D5)

# Scan for sensors and grab the first one found.
ds18_0 = DS18X20(ow_bus, ow_bus.scan()[0])
ds18_1 = DS18X20(ow_bus, ow_bus.scan()[1])
# devices = ow_bus.scan()
# for device in devices:
#     print("ROM = {} \tFamily = 0x{:02x}".format([hex(i) for i in device.rom], device.family_code))

# SetUp NeoPixels
tempLEDPin = board.A1
numLED = 16
ORDER = neopixel.GRB
import board
import time
import simpleio
#import pulseio

#buzzer = pulseio.PWMOut(board.D3, frequency=2500, duty_cycle=0)
pump = simpleio.DigitalOut(board.D0)

def cyclePump():
    # Ultimately the timing for on/off will be more like 30 on and 3600 off.
    pump.value = True
    time.sleep(15)
    pump.value = False

#def makeBeep():
#    #mostly for learning purposes, but emits a quick beep pattern - disable when running via battery?
#    buzzer.duty_cycle = 30000
#    time.sleep(0.08)
#    buzzer.duty_cycle = 65535
#    time.sleep(0.1)
#    buzzer.duty_cycle = 30000
#    time.sleep(0.08)
#    buzzer.duty_cycle = 0


def generateO2():
#    makeBeep()
    cyclePump()

while True:
    generateO2()
示例#4
0
        elif empty_pos and PREY_MOVES:
            self.grid[empty_pos[0]][empty_pos[1]] = prey
            self.grid[r][c] = Cell(CELL_EMPTY)
            changed = True
        return changed


def reset_world(world):
    global PREDATOR_HUE
    global PREY_HUE
    PREDATOR_HUE = rand_hue()
    PREY_HUE = rand_hue()
    world.reset_grid()


board_led = simpleio.DigitalOut(BOARD_LED)
board_led.value = True
world = World()
reset_world(world)

# start_secs = time.monotonic()
# start_frames = 0
while True:
    # print(FRAME_COUNT)
    board_led.value = not board_led.value
    changed = world.step()
    world.draw()
    FRAME_COUNT += 1

    # total_secs = time.monotonic() - start_secs
    # if total_secs > 10: