Exemple #1
0
 def __init__(self):
     # Configure the Thermistor for reading the temperature
     self._thermistor = adafruit_thermistor.Thermistor(
         board.TEMPERATURE, 10000, 10000, 25, 3950)
     self._light = analogio.AnalogIn(board.LIGHT)
     self._enabled = False
     self._data = [0, 0, 0]
Exemple #2
0
 def __init__(self):
     self.buttonA = digitalio.DigitalInOut(board.BUTTON_A)
     self.buttonB = digitalio.DigitalInOut(board.BUTTON_B)
     self.buttonA.switch_to_input(pull=digitalio.Pull.DOWN)
     self.light = analogio.AnalogIn(board.LIGHT)
     self.thermistor = adafruit_thermistor.Thermistor(
         board.TEMPERATURE, 10000, 10000, 25, 3950)
Exemple #3
0
def main():
    LEDS_COUNT = 10
    pixels = neopixel.NeoPixel(board.NEOPIXEL,
                               10,
                               brightness=0.1,
                               auto_write=True)
    thermistor = adafruit_thermistor.Thermistor(board.TEMPERATURE, 10000,
                                                10000, 25, 3950)
    button_a = digitalio.DigitalInOut(board.BUTTON_A)
    button_a.direction = digitalio.Direction.INPUT
    button_a.pull = digitalio.Pull.DOWN
    button_b = digitalio.DigitalInOut(board.BUTTON_B)
    button_b.direction = digitalio.Direction.INPUT
    button_b.pull = digitalio.Pull.DOWN
    temperature_min = thermistor.temperature
    temperature_delta_max = 4
    while True:
        temperature = thermistor.temperature
        temperature_percent = minmax(
            (temperature - temperature_min) / temperature_delta_max)
        print('temperature_percent: {}'.format(temperature_percent))
        rgb_color = temperature_percent_to_color255(temperature_percent)
        leds_on = int(temperature_percent * LEDS_COUNT)
        for led_index in range(LEDS_COUNT):
            if led_index <= leds_on:
                pixels[led_index] = rgb_color
            else:
                pixels[led_index] = (0, 0, 0)
        time.sleep(0.1)
Exemple #4
0
    def __init__(self):
        self._a = digitalio.DigitalInOut(board.BUTTON_A)
        self._a.switch_to_input(pull=digitalio.Pull.DOWN)
        self._b = digitalio.DigitalInOut(board.BUTTON_B)
        self._b.switch_to_input(pull=digitalio.Pull.DOWN)
        self.gamepad = gamepad.GamePad(self._a, self._b)

        # Define switch:
        self._switch = digitalio.DigitalInOut(board.SLIDE_SWITCH)
        self._switch.switch_to_input(pull=digitalio.Pull.UP)

        # Define LEDs:
        self._led = digitalio.DigitalInOut(board.D13)
        self._led.switch_to_output()
        self._pixels = neopixel.NeoPixel(board.NEOPIXEL, 10)

        # Define sensors:
        self._temp = adafruit_thermistor.Thermistor(
            board.TEMPERATURE, 10000, 10000, 25, 3950
        )
        self._light = Photocell(board.LIGHT)

        # Define touch:
        # Initially, self._touches stores the pin used for a particular touch. When that touch is
        # used for the first time, the pin is replaced with the corresponding TouchIn object.
        # This saves a little RAM over using a separate read-only pin tuple.
        # For example, after `cp.touch_A2`, self._touches is equivalent to:
        # [None, board.A1, touchio.TouchIn(board.A2), board.A3, ...]
        # Slot 0 is not used (A0 is not allowed as a touch pin).
        self._touches = [
            None,
            board.A1,
            board.A2,
            board.A3,
            board.A4,
            board.A5,
            board.A6,
            board.TX,
        ]
        self._touch_threshold_adjustment = 0

        # Define acceleration:
        self._i2c = busio.I2C(board.ACCELEROMETER_SCL, board.ACCELEROMETER_SDA)
        self._int1 = digitalio.DigitalInOut(board.ACCELEROMETER_INTERRUPT)
        self._lis3dh = adafruit_lis3dh.LIS3DH_I2C(
            self._i2c, address=0x19, int1=self._int1
        )
        self._lis3dh.range = adafruit_lis3dh.RANGE_8_G

        # Define audio:
        self._speaker_enable = digitalio.DigitalInOut(board.SPEAKER_ENABLE)
        self._speaker_enable.switch_to_output(value=False)
        self._sample = None
        self._sine_wave = None
        self._sine_wave_sample = None

        # Initialise tap:
        self._detect_taps = 1
        self.detect_taps = 1
    def __init__(self):
        # Only create the cpx module member when we're aren't being imported by Sphinx
        if ("__module__" in dir(digitalio.DigitalInOut)
                and digitalio.DigitalInOut.__module__ == "sphinx.ext.autodoc"):
            return
        self._a = digitalio.DigitalInOut(board.BUTTON_A)
        self._a.switch_to_input(pull=digitalio.Pull.DOWN)
        self._b = digitalio.DigitalInOut(board.BUTTON_B)
        self._b.switch_to_input(pull=digitalio.Pull.DOWN)

        # Define switch:
        self._switch = digitalio.DigitalInOut(board.SLIDE_SWITCH)
        self._switch.switch_to_input(pull=digitalio.Pull.UP)

        # Define LEDs:
        self._led = digitalio.DigitalInOut(board.D13)
        self._led.switch_to_output()
        self._pixels = neopixel.NeoPixel(board.NEOPIXEL, 10)

        # Define sensors:
        self._temp = adafruit_thermistor.Thermistor(board.TEMPERATURE, 10000,
                                                    10000, 25, 3950)
        self._light = Photocell(board.LIGHT)

        # Define audio:
        self._speaker_enable = digitalio.DigitalInOut(board.SPEAKER_ENABLE)
        self._speaker_enable.switch_to_output(value=False)
        self._sample = None
        self._sine_wave = None

        # Define touch:
        # We chose these verbose touch_A# names so that beginners could use it without understanding
        # lists and the capital A to match the pin name. The capitalization is not strictly Python
        # style, so everywhere we use these names, we whitelist the errors using:
        # pylint: disable=invalid-name
        self._touch_A1 = None
        self._touch_A2 = None
        self._touch_A3 = None
        self._touch_A4 = None
        self._touch_A5 = None
        self._touch_A6 = None
        self._touch_A7 = None
        self._touch_threshold_adjustment = 0

        # Define acceleration:
        self._i2c = busio.I2C(board.ACCELEROMETER_SCL, board.ACCELEROMETER_SDA)
        self._int1 = digitalio.DigitalInOut(board.ACCELEROMETER_INTERRUPT)
        try:
            self._lis3dh = adafruit_lis3dh.LIS3DH_I2C(self._i2c,
                                                      address=0x19,
                                                      int1=self._int1)
        except TypeError:
            self._lis3dh = adafruit_lis3dh.LIS3DH_I2C(self._i2c, address=0x19)
        self._lis3dh.range = adafruit_lis3dh.RANGE_8_G

        # Initialise tap:
        self._detect_taps = 1
        self.detect_taps = 1
def init():
    global thermistor
    global initialized
    if initialized:
        #print("already initialized")
        return 0
    #print("initializing thermistor")
    thermistor = adafruit_thermistor.Thermistor(board.TEMPERATURE, 10000, 10000, 25, 3950)
    initialized = True
    def __init__(self):
        # Only create the circuit module member when we're aren't being imported by Sphinx
        if "__module__" in dir(
                digitalio.DigitalInOut
        ) and digitalio.DigitalInOut.__module__ == "sphinx.ext.autodoc":
            return
        self._a = digitalio.DigitalInOut(board.BUTTON_A)
        self._a.switch_to_input(pull=digitalio.Pull.DOWN)
        self._b = digitalio.DigitalInOut(board.BUTTON_B)
        self._b.switch_to_input(pull=digitalio.Pull.DOWN)

        # Define switch:
        self._switch = digitalio.DigitalInOut(board.SLIDE_SWITCH)
        self._switch.switch_to_input(pull=digitalio.Pull.UP)

        # Define LEDs:
        self._led = digitalio.DigitalInOut(board.D13)
        self._led.switch_to_output()
        self.pixels = neopixel.NeoPixel(board.NEOPIXEL, 10)
        """Sequence like object representing the ten NeoPixels around the outside
        of the CircuitPlayground. Each pixel is at a certain index in the sequence
        as labeled below. Colors can be RGB hex like 0x110000 for red where each
        two digits are a color (0xRRGGBB) or a tuple like (17, 0, 0) where (R, G, B).

        See `neopixel.NeoPixel` for more info.

        .. image :: /_static/neopixel_numbering.jpg
            :alt: NeoPixel order diagram

        Here is an example that sets the first pixel green and the second red.

        .. code-block:: python

          from adafruit_circuitplayground.express import circuit

          circuit.pixels[0] = 0x000300
          circuit.pixels[9] = 0x030000

          # Wait forever. CTRL-C to quit.
          while True:
              pass
        """

        # Define sensors:
        self._temp = adafruit_thermistor.Thermistor(board.TEMPERATURE, 10000,
                                                    10000, 25, 3950)
        self._light = Photocell(board.LIGHT)

        # Define audio:
        self.speaker_enable = digitalio.DigitalInOut(board.SPEAKER_ENABLE)
        self.speaker_enable.switch_to_output(value=False)
Exemple #8
0
# setup.py for the CircuitPlayground Express
import board
import neopixel
import adafruit_thermistor
from digitalio import DigitalInOut, Direction, Pull
import analogio

thermistor = adafruit_thermistor.Thermistor(board.TEMPERATURE,
                                            10000.0,
                                            10000.0,
                                            25.0,
                                            3950.0,
                                            high_side=False)
photocell = analogio.AnalogIn(board.LIGHT)

led = DigitalInOut(board.D13)
led.direction = Direction.OUTPUT

rgb = neopixel.NeoPixel(board.NEOPIXEL, 10)
rgb.brightness = 0.1

a_button = DigitalInOut(board.D4)
a_button.direction = Direction.INPUT
a_button.pull = Pull.DOWN

b_button = DigitalInOut(board.D5)
b_button.direction = Direction.INPUT
b_button.pull = Pull.DOWN


def check(token):
Exemple #9
0
import time
import board
import analogio
import adafruit_thermistor
import neopixel
from progspace_room import Room

room = Room(use_debug=False)
thermistor = adafruit_thermistor.Thermistor(board.TEMPERATURE, 10000, 10000,
                                            25, 3950)
light = analogio.AnalogIn(board.LIGHT)
pixels = neopixel.NeoPixel(board.NEOPIXEL,
                           10,
                           brightness=0.2,
                           auto_write=False)


def scale(value):
    """Scale the light sensor values from 0-65535 (AnalogIn range)
    to 0-50 (arbitrarily chosen to plot well with temperature)"""
    return value / 65535 * 50


def when_callback(results):
    print("WHEN CALLBACK: {}".format(results))
    if len(results) > 0 and 't' in results[0]:
        try:
            t = int(results[0]['t'])
            for i in range(len(pixels)):
                if t % len(pixels) == i:
                    pixels[i] = (0, 255, 0)
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT

import time
import board
import adafruit_thermistor

# these values work with the Adafruit CircuitPlayground Express.
# they may work with other thermistors as well, as they're fairly standard,
# though the pin will likely need to change (ie board.A1)
# pylint: disable=no-member
pin = board.TEMPERATURE
resistor = 10000
resistance = 10000
nominal_temp = 25
b_coefficient = 3950

thermistor = adafruit_thermistor.Thermistor(
    pin, resistor, resistance, nominal_temp, b_coefficient
)

# print the temperature in C and F to the serial console every second
while True:
    celsius = thermistor.temperature
    fahrenheit = (celsius * 9 / 5) + 32
    print("== Temperature ==\n{} *C\n{} *F\n".format(celsius, fahrenheit))
    time.sleep(1)
Exemple #11
0
import time

import neopixel
import adafruit_thermistor

### this code does not belong here
##ser = serial.Serial('/dev/ttyAMA0')

### Inspire by https://learn.adafruit.com/adafruit-circuit-playground-express/playground-temperature
### Some values specific to CPX
series_resistor = 10000
nominal_resistance = 10000
nominal_temperature = 25
b_coefficient = 3950
thermistor = adafruit_thermistor.Thermistor(board.TEMPERATURE, series_resistor,
                                            nominal_resistance,
                                            nominal_temperature, b_coefficient)

redled = digitalio.DigitalInOut(board.D13)
redled.direction = digitalio.Direction.OUTPUT

black = (0, 0, 0)
cyan = (0, 0x20, 0x20)
yellow = (0x20, 0x20, 0)
red = (0x20, 0, 0)
green = (0, 0x20, 0)
magenta = (0x20, 0, 0x20)
blue = (0, 0, 0x20)
white = (0x20, 0x20, 0x20)

### CPX has 10 leds
Exemple #12
0
# setup.py For The Trinket M0
import board
from digitalio import DigitalInOut, Direction, Pull
import adafruit_dotstar
import adafruit_thermistor
import analogio

thermistor = adafruit_thermistor.Thermistor(board.D3,
                                            10000.0,
                                            10000.0,
                                            25.0,
                                            3950.0,
                                            high_side=False)
photocell = analogio.AnalogIn(board.D0)

led = DigitalInOut(board.D13)
led.direction = Direction.OUTPUT

rgb = adafruit_dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1)
rgb.brightness = 0.3

a_button = DigitalInOut(board.D1)
a_button.direction = Direction.INPUT
a_button.pull = Pull.UP

b_button = DigitalInOut(board.D2)
b_button.direction = Direction.INPUT
b_button.pull = Pull.UP


def check(token):
import board
import digitalio
import adafruit_lis3dh
import touchio
import time
import neopixel
import adafruit_thermistor

pixels = neopixel.NeoPixel(board.NEOPIXEL, 10, brightness=0.2)

i2c = board.I2C()
int1 = digitalio.DigitalInOut(board.ACCELEROMETER_UNTERRUPT)
lis3dh = adafruit_lis3dh.LIS3DH_I2C(i2c, int1=int1)

circuit_playground_temperature = adafruit_thermistor.Thermistor(board.TEMPERATURE, 10000, 10000, 25, 3950)

touch_A1 = touchio.TouchIn(board.A1)
touch_A2 = touchio.TouchIn(board.A2)

led = digitalio.DigitalInOut(board.D13)
led.direction = digitalio.Direction.OUTPUT

button_A = digitalio.DigitalInOut(board.BUTTON_A)
button_A.direction = digitalio.Direction.INPUT
button_A.pull = digitalio.Pull.DOWN

while True:
    x, y, z = lis3dh.acceleration

    if button_A.value:
        led.value = True
Exemple #14
0
    """ Initialise RGB colour list. """
    colour = [0, 0, 0]
    """ Initialise scheduling variables. """
    """ Initialise neopixels
        brightness is a value from 0-1
        auto_write = True means the pixels
        value change without show,
        but is extremely slow
    """
    pixels = neopixel.NeoPixel(board.NEOPIXEL,
                               c.NUM_PIXELS,
                               brightness=1,
                               auto_write=False)
    """ Initialise thermistor. """
    thermistor = adafruit_thermistor.Thermistor(board.TEMPERATURE, c.RMEASURED,
                                                c.NOMINALRESISTOR,
                                                c.NOMINALTEMPERATURE,
                                                c.BETACOEF)
    """ Initialise light ADC. """
    light = AnalogIn(board.LIGHT)
    """ Initialise sound measurements. """
    mic = audiobusio.PDMIn(board.MICROPHONE_CLOCK,
                           board.MICROPHONE_DATA,
                           sample_rate=c.SAMPLE_RATE,
                           bit_depth=c.BIT_DEPTH)
    # Record an initial sample to calibrate. Assume it's quiet when we start.
    # TODO: this is dangerous, get rid of it
    # an array of unsigned shorts ('H')
    samples = array.array('H', [0] * c.NUM_SAMPLES)
    mic.record(samples, len(samples))

# Set lowest level to expect, plus a little.
led.direction = digitalio.Direction.OUTPUT

relay = digitalio.DigitalInOut(relayPin)
relay.switch_to_output()

motionSensor = digitalio.DigitalInOut(motionSensorPin)
motionSensor.switch_to_input()
lastMotionSensorValue = motionSensor.value
motionSensorStartTime = time.time()
motionSensorEndTime = motionSensorStartTime

analogVelostat = analogio.AnalogIn(analogVelostatPin)

light = analogio.AnalogIn(lightSensorPin)

thermistor = adafruit_thermistor.Thermistor(thermistorPin, 10000, 10000, 25,
                                            3950)

onboardpixels = local.SetupOnboardNeopixels()

numPixels = 30
strandpixels = local.SetupNeopixelsStrand(strandPixelPin, 30)

peakColor = (100, 0, 255)  # Color of the peak pixel for audio display
mic = audiobusio.PDMIn(board.MICROPHONE_CLOCK,
                       board.MICROPHONE_DATA,
                       sample_rate=16000,
                       bit_depth=16)
input_floor = 50  # Example adapts from the first read
input_ceiling = input_floor + 500
peak = 0