Esempio n. 1
0
def init_APA102():
    global DOTSTAR
    # Configure SPI for controlling the DotStar
    # Internally we are using software SPI for this as the pins being used are not hardware SPI pins
    spi = SoftSPI(sck=Pin(TinyPICO.DOTSTAR_CLK),
                  mosi=Pin(TinyPICO.DOTSTAR_DATA),
                  miso=Pin(TinyPICO.SPI_MISO))
    # Create a DotStar instance
    DOTSTAR = DotStar(spi, 1,
                      brightness=0.4)  # Just one DotStar, half brightness
    # Turn on the power to the DotStar
    TinyPICO.set_dotstar_power(True)
    return True
Esempio n. 2
0
from machine import Pin, SoftSPI
import tinypico as TinyPICO
from dotstar import DotStar
import time, random, micropython, gc

# Configure SPI for controlling the DotStar
# Internally we are using software SPI for this as the pins being used are not hardware SPI pins
spi = SoftSPI(sck=Pin(TinyPICO.DOTSTAR_CLK),
              mosi=Pin(TinyPICO.DOTSTAR_DATA),
              miso=Pin(TinyPICO.SPI_MISO))

# Create a DotStar instance
dotstar = DotStar(spi, 1, brightness=0.5)  # Just one DotStar, half brightness

# Turn on the power to the DotStar
TinyPICO.set_dotstar_power(True)

# Say hello
print("\nHello from TinyPICO!")
print("--------------------\n")

# Show some info on boot
print("Battery Voltage is {}V".format(TinyPICO.get_battery_voltage()))
print("Battery Charge State is {}\n".format(TinyPICO.get_battery_charging()))

# Show available memory
print("Memory Info - micropython.mem_info()")
print("------------------------------------")
micropython.mem_info()

# Create a colour wheel index int
Esempio n. 3
0
File: board.py Progetto: tve/mqboard
def define_led():
    global act_led, fail_led, bat_volt_pin, bat_fct
    if kind == "tve-bare":
        # bare esp32-wroom module with LED across IO23 and gnd
        lpin = machine.Pin(23, machine.Pin.OUT, None, value=0)
        led = lambda v: lpin(v)
        act_led, fail_led = (led, led)
    elif kind == "huzzah32":
        # Adafruit Huzzah32 feather
        lpin = machine.Pin(13, machine.Pin.OUT, None, value=0)
        led = lambda v: lpin(v)
        fail_led = led
    elif kind == "esp32-sim1":
        # TvE custom ESP32 SIM module v1
        lpin1 = machine.Pin(2, machine.Pin.OUT, None, value=1)
        act_led = lambda v: lpin1(v)
        lpin2 = machine.Pin(5, machine.Pin.OUT, None, value=1)
        fail_led = lambda v: lpin2(not v)
        bat_volt_pin = machine.ADC(machine.Pin(35))
        bat_volt_pin.atten(machine.ADC.ATTN_11DB)
    elif kind == "lolin-d32":
        # Wemos Lolin D-32
        lpin = machine.Pin(5, machine.Pin.OUT, None, value=1)
        led = lambda v: lpin(not v)
        bat_volt_pin = machine.ADC(machine.Pin(35))
        bat_volt_pin.atten(machine.ADC.ATTN_11DB)
        act_led, fail_led = (led, led)
    elif kind == "nodemcu":
        # NodeMCU
        lpin = machine.Pin(2, machine.Pin.OUT, None, value=0)
        led = lambda v: lpin(v)
        act_led, fail_led = (led, led)
    elif kind == "esp32thing":
        # Sparkfun ESP32 Thing
        lpin = machine.Pin(5, machine.Pin.OUT, None, value=0)
        led = lambda v: lpin(v)
        act_led, fail_led = (led, led)
    elif kind == "ezsbc":
        # EzSBC
        lpin1 = machine.Pin(19, machine.Pin.OUT, None, value=1)
        act_led = lambda v: lpin1(not v)
        lpin2 = machine.Pin(16, machine.Pin.OUT, None, value=1)
        fail_led = lambda v: lpin2(not v)
    elif kind == "tinypico":
        # TinyPICO has an RGB LED so we use the red channel for WiFi and the blue
        # channel for message rx
        from machine import SPI, Pin
        import tinypico as TinyPICO
        from dotstar import DotStar

        spi = SPI(
            sck=Pin(TinyPICO.DOTSTAR_CLK),
            mosi=Pin(TinyPICO.DOTSTAR_DATA),
            miso=Pin(TinyPICO.SPI_MISO),
        )
        dotstar = DotStar(spi, 1, brightness=0.5)  # Just one DotStar, half brightness
        TinyPICO.set_dotstar_power(True)

        color = [255, 0, 0]

        def set_red(v):
            color[0] = 255 if v else 0
            dotstar[0] = color

        def set_blue(v):
            color[2] = 255 if v else 0
            dotstar[0] = color

        fail_led = set_red
        act_led = set_blue
    elif kind == "pybd":
        from pyb import LED

        def led(n, v):
            if v:
                LED(n).on()
            else:
                LED(n).off()

        act_led = lambda v: led(3, v)
        fail_led = lambda v: led(1, v)
Esempio n. 4
0
"""
# CTRL-C : Wire X9 to the ground via a Push-Button
# CTRL-V : Wire X10 to the ground via a Push-Button
from machine import Pin, SPI
from pyb import LED
import pyb
from kmap_frbe import kmap, CTRL, SHIFT, CTRL_RIGHT, SHIFT_RIGHT
from usbhid import *
from dotstar import DotStar
from time import sleep_ms

hid = pyb.USB_HID()
spi = SPI(sck=Pin("S23", Pin.OUT),
          mosi=Pin("S19", Pin.OUT),
          miso=Pin("S21", Pin.OUT))
leds = DotStar(spi, 3)
leds.fill((80, 80, 80))


class Btn():
    """ Button with software debouncing. Count the number of time a button is
        pressed. Have a reject_ms to reject several button within a given
        timelapse. """
    def __init__(self, pin, reject_ms=200):
        self.pin = pin
        self.counter = 0
        self.last_millis = 0
        self.reject_ms = 200
        self.state = pin.value()

    def update(self):
Esempio n. 5
0
    for i in range(4):
        dotstar.brightness = LED_BRIGHTNESS
        time.sleep(0.05)
        dotstar.brightness = 0
        time.sleep(0.05)


button_pad = TouchPad(Pin(BUTTON_TOUCHPAD_PIN))

ir_transmitter = IRTransmitter(Pin(TRANSMITTER_PIN))
wlan = network.WLAN(network.STA_IF)

spi = SPI(sck=Pin(TinyPICO.DOTSTAR_CLK),
          mosi=Pin(TinyPICO.DOTSTAR_DATA),
          miso=Pin(TinyPICO.SPI_MISO))
dotstar = DotStar(spi, 1, brightness=0.0)
dotstar[0] = (0, 188, 255, 0.5)
TinyPICO.set_dotstar_power(True)

syncing = True
ac_on = None
button_cooldown_time = 0

connect()
blynk = blynklib.Blynk(secret.BLYNK_AUTH, log=print)


@blynk.handle_event("write V" + str(BUTTON_VPIN))
def write_handler(pin, value):
    global ac_on
Esempio n. 6
0
import urequests
import uos
from purpleair import PurpleAir

try:
    directoryContents = uos.listdir('.')
    if 'log.bak.csv' in directoryContents:
        uos.remove('log.bak.csv')
    if 'log.csv' in directoryContents:
        uos.rename('log.csv', 'log.csv.bak')
    print('logs ready')
except:
    print('error cleaning logs')

spi = SPI(sck=Pin(12), mosi=Pin(2), miso=Pin(19))
dstar = DotStar(spi, 1) # Just one DotStar
dstar[0] = (32, 0, 0)

class WiFi():
    ssid = ''
    password = ''
    wlan = network.WLAN( network.STA_IF )
    
    def __init__(self, configs):
        self.ssid = configs['ssid']
        self.password = configs['password']
    def connect(self):
        self.wlan.active(True)
        self.wlan.connect(self.ssid, self.password)
        while not self.wlan.isconnected:
            pass