예제 #1
0
파일: M5GO.py 프로젝트: shaxser/M5GO
def rgbled_start(obj):
  lcd.image(0, 0, '/flash/img/3-4.jpg', type=lcd.JPG)
  np = machine.Neopixel(machine.Pin(15), 10)
  np.brightness(1)
  np.set(1, lcd.RED, num=5)
  np.set(6, lcd.BLUE, num=10)
  obj['np'] = np
  obj['upinc'] = True
  obj['led_right'] = 0
예제 #2
0
 def __init__(self):
     if sys.implementation.name != "micropython":
         raise OSError("This is not micropython")
     import machine
     self.neopixel = machine.Neopixel(27, 1)
     self.rainbow = [machine.Neopixel.BLACK, machine.Neopixel.BLUE,
                     machine.Neopixel.RED, machine.Neopixel.MAGENTA,
                     machine.Neopixel.GREEN, machine.Neopixel.CYAN,
                     machine.Neopixel.YELLOW, machine.Neopixel.WHITE]
     self.pointer = 0
예제 #3
0
파일: M5GO.py 프로젝트: shaxser/M5GO
def angle_start(obj):
  lcd.image(0, 0, '/flash/img/3-9.jpg', type=lcd.JPG)
  np = machine.Neopixel(machine.Pin(15), 10)
  np.brightness(0)
  np.set(1, lcd.WHITE, num=10)
  obj['np'] = np
  obj['angle'] = units.ANGLE(units.PORTB)
  obj['prev'] = 0
  dac = machine.DAC(machine.Pin(25))
  dac.write(0)
  lcd.font(lcd.FONT_DejaVu24)
예제 #4
0
파일: M5GO.py 프로젝트: shaxser/M5GO
def startup_start(obj):
  lcd.image(0, 0, '/flash/img/1-1.jpg')
  lcd.setColor(lcd.BLACK, lcd.WHITE)
  lcd.font(lcd.FONT_DejaVu24)
  np = machine.Neopixel(machine.Pin(15), 10)
  np.brightness(1)
  np.set(1, 0xffffff, num=10)
  obj['np'] = np
  obj['brs'] = 0
  obj['lcdbrs'] = 10
  obj['dect'] = True
  obj['timeout'] = time.ticks_ms() + 4000
    def __init__(self, port=PORTB, number=143):
        global rgb_muti_porta, rgb_muti_portb, rgb_muti_portc
        if port == PORTB and rgb_muti_portb != None:
            rgb_muti_portb.deinit()
        elif port == PORTA and rgb_muti_porta != None:
            rgb_muti_porta.deinit()
        elif port == PORTC and rgb_muti_portc != None:
            rgb_muti_portc.deinit()
        self.port = port
        self.pin = port[0]
        self.number = number
        self.np = machine.Neopixel(self.pin, self.number)
        self.np.brightness(10, update=False)
        self.np.show()
        time.sleep_ms(10)

        if port == PORTA:
            rgb_muti_porta = self.np
        elif port == PORTB:
            rgb_muti_portb = self.np
        elif port == PORTC:
            rgb_muti_portc = self.np
예제 #6
0
                                "Interval set to {} seconds".format(interval))

            time.sleep_ms(100)
        send_time = send_time + interval
        if sendmsg:
            _thread.sendmsg(_thread.getReplID(), bmevalues())


# 3K is enough for BME280 thread
_ = _thread.stack_size(3 * 1024)
# start the BME280 thread
bmeth = _thread.start_new_thread("BME280", bmerun, (60, ))

# === In the 3rd thread we will run Neopixels rainbow demo ===

np = machine.Neopixel(machine.Pin(22), 24)


# DEfine Neopixels thread function
#---------------
def thrainbow():
    pos = 0
    bri = 0.02
    while True:
        for i in range(0, 24):
            dHue = 360.0 / 24 * (pos + i)
            hue = dHue % 360
            np.setHSB(i, hue, 1.0, bri, 1, False)
        np.show()
        notif = _thread.getnotification()
        if (notif > 0) and (notif <= 100):
예제 #7
0
                _thread.sendmsg(_thread.getReplID(), "Interval set to {} seconds".format(interval))
                
            time.sleep_ms(100)
        send_time = send_time + interval
        if sendmsg:
            _thread.sendmsg(_thread.getReplID(), bmevalues())

# 3K is enough for BME280 thread
_ = _thread.stack_size(3*1024)
# start the BME280 thread
bmeth=_thread.start_new_thread("BME280", bmerun, (60,))

# === In the 3rd thread we will run Neopixels rainbow demo ===

num_np = 144
np=machine.Neopixel(machine.Pin(21), num_np)

def rainbow(pos=1, bri=0.02):
    dHue = 360*3/num_np
    for i in range(1, num_np):
        hue = (dHue * (pos+i)) % 360;
        np.setHSB(i, hue, 1.0, bri, 1, False)
    np.show()

# DEfine Neopixels thread function
#-----------------
def thrainbow_py():
    pos = 0
    bri = 0.02
    while True:
        for i in range(0, num_np):
예제 #8
0
import machine, time
from RGB565RGB import *

#define
np = machine.Neopixel(2, 64, 0)


def rainbow(length=64, loops=120, delay=1, sat=1.0, bri=0.2):
    for pos in range(0, loops):
        for i in range(1, length + 1):
            dHue = 360.0 / 24 * (pos + i)
            hue = dHue % 360
            np.setHSB(i, hue, sat, bri, 1, False)
        np.show()
        if delay > 0:
            time.sleep_ms(delay)


def blinkRainbow(length=64, loops=10, delay=250):
    for pos in range(0, loops):
        for i in range(1, length + 1):
            dHue = 360.0 / length * (pos + i)
            hue = dHue % 360
            np.setHSB(i, hue, 1.0, 0.1, 1, False)
        np.show()
        time.sleep_ms(delay)
        np.clear()
        time.sleep_ms(delay)


rainbow(delay=200)
예제 #9
0
import machine, _thread
import utime, random, math

led_pin = machine.Pin(14, machine.Pin.OUT)
num_pixels = 14

strip = machine.Neopixel(pin=led_pin, pixels=num_pixels, type=1)


def set_brightness(brightness_val):
    strip.brightness(brightness_val)


def waitForExitNotification(timeout):
    """ waitForExitNotification(timeout)
    uses _thread.wait(timeout) to sleep for amount of ms saved in timeout and
    checks notfication for _thread.EXIT notification. Returns True if
    _thread.EXIT notification is recieved, else returns False

    timeout: (ms) time in ms used for _thread.wait()
    return: (boolean) True if _thread.EXIT is recieved, else False.
    """
    notification = _thread.wait(timeout)
    if notification == _thread.EXIT:
        strip.set(0, 0x00, num=num_pixels)
        print("stopping animation")
        return True
    else:
        return False

예제 #10
0
import machine, time

np = machine.Neopixel(machine.Pin(5), 256, 0)


def rainbow(loops=120, delay=1, sat=1.0, bri=0.2):
    for pos in range(0, loops):
        for i in range(0, 256):
            #for i in range(0, 24):
            dHue = 360.0 / 256 * (pos + i)
            hue = dHue % 360
            np.setHSB(i, hue, sat, bri, 1, False)
        np.show()
        if delay > 0:
            time.sleep_ms(delay)


def blinkRainbow(loops=10, delay=250):
    for pos in range(0, loops):
        for i in range(0, 24):
            dHue = 360.0 / 256 * (pos + i)
            hue = dHue % 360
            np.setHSB(i, hue, 1.0, 0.1, 1, False)
        np.show()
        time.sleep_ms(delay)
        np.clear()
        time.sleep_ms(delay)


rainbow(loops=100, delay=1, bri=0.05)
#blinkRainbow(loops=1000, delay=1, bri=0.05)
예제 #11
0
 def __init__(self, port, number=143):
     self.port = port
     self.pin = port[0]
     self.number = number
     self.np = machine.Neopixel(self.pin, self.number)
     self.np.brightness(10)
예제 #12
0
import machine
import time
#to improve error reporting during callbacks
import micropython
micropython.alloc_emergency_exception_buf(100)

np = machine.Neopixel(15, 24)

#simple Blocking
while True:
    # Set color for pixel 0 (pure red)
    for n in range(1, 10):
        np.set(n, np.RED)
        time.sleep(0.1)
    for n in range(1, 10):
        np.set(n, np.GREEN)
        time.sleep(0.1)
    for n in range(1, 10):
        np.set(n, np.MAGENTA)
        time.sleep(0.1)

#global vars
pos = 0
sat = 1.0
bri = 0.2
loops = 120
t3 = machine.Timer(3)


def rainbow_cb(timer):
    global sat, bri, pos, loops
예제 #13
0
from machine import Neopixel, I2C, Pin, Timer
from board import SDA, SCL
from umqtt.simple import MQTTClient
from time import sleep
import machine
import time
import adafruit_bme680

STATUS = "TEMP"
HEX_COLOR = "#000000"

# create NeoPixel driver on GPIO0 for 60 pixels
np_count = 60
np = machine.Neopixel(machine.Pin(27), np_count, 0)

myMqttClient = b"Hello"
BROKER = b"io.adafruit.com"
adafruitUsername = b"alexiswei"
adafruitAioKey = b"82c482a0b0d14defaeccfaecae62ae36"
mqtt = MQTTClient(myMqttClient, BROKER, 0, adafruitUsername, adafruitAioKey)


def sub_cb(topic, msg):
    global STATUS, HEX_COLOR
    print((topic, msg))
    if topic == b'alexiswei/feeds/mode':
        if msg == b'TEMP':
            print('changed to temp')
            #read from the temperature sensor
            STATUS = 'TEMP'
        elif msg == b'COLOR':
예제 #14
0
from m5stack import *
import machine, _thread

np = machine.Neopixel(machine.Pin(15), 10)
np.set(1, lcd.WHITE, num=10)

# def rainbow(loops=120, delay=20, sat=1.0, bri=0.2):
#     for pos in range(0, loops):
#         for i in range(0, 10):
#             dHue = 360.0/10*(pos+i);
#             hue = dHue % 360;
#             np.setHSB(i, hue, sat, bri, 1, False)
#         np.show()
#         if delay > 0:
#             time.sleep_ms(delay)

# def startup_led_show():
#   np.brightness(255)
#   rainbow(loops=10000, delay=40, sat=1.0, bri=0.2)
# _thread.start_new_thread('startup_led_show', startup_led_show, ())

# -------- microphone --------
mic_adc = 0
buffer = []


def microphone_enter():
    print('microphone_enter')
    global mic_adc, buffer
    try:
        mic_adc = machine.ADC(34)
예제 #15
0
import uos, machine, time

np = machine.Neopixel(machine.Pin(27), 1) 
np.set(0, 0xFF0000)
np.show()
import network
import gc

#connect
sta = network.WLAN(network.STA_IF)
sta.active(True)
wlan=list()
with open( 'credentials.txt','r') as f:
    # this file should contain ssid<space>pw, one per line
    line=f.readline().strip().split()
    while line:
        wlan.append(line)
        line=f.readline().strip().split()
if machine.wake_reason()[0] not in [4,6]:#Soft reset
    # this should help reconnecting... not sure whether it works or not
    # configuration below MUST match your home router settings!!
    print('configure wlan')
    sta.ifconfig(('192.168.178.53', '255.255.255.0', '192.168.178.1', '8.8.8.8'))
    
timeout=5000 #5 seconds
if not sta.isconnected():
    # try all wlans from the file
    # todo: scan first and check which can be seen
    for pw in wlan:    
        start = time.ticks_ms()
        while not sta.isconnected():
예제 #16
0
from lib.light_object import LightObject
from lib.tile import Tile
from lib.tile_collection import TileCollection
from effect_handler import EffectHandler
import gc
from serial import Serial

log.info("MAIN", "Libraries loaded. Initializing ...")

gc.threshold(70000)
machine.freq(240000000)

led_data_power_control = machine.Pin(19, machine.Pin.OUT)
led_data_power_control.value(1)

neopixel = machine.Neopixel(machine.Pin(5), 300, machine.Neopixel.TYPE_RGBW)

color.np = neopixel
neopixel.clear()
neopixel.brightness(255)

tiles = []

xy = [(0, 1), (1, 1), (2, 1), (3, 1), (4, 1),
      (4, 0), (5, 0), (6, 0), (6, 1), (1, 12)]

for i in range(len(xy)):
    tiles.append(Tile(xy[i][0], xy[i][1], LightObject(
        neopixel, 1+i*15, 5, corner_count=3, active_led_count_per_corner=5)))

tile_collection = TileCollection(tiles)
예제 #17
0
파일: ledring.py 프로젝트: tebanski/M5GO
import machine, time
led_bar = machine.Neopixel(15, 10)
while True:
    for i in range(1, 11):
        if i > 0:
            led_bar.set(i, led_bar.BLACK)  # OFF
        if i + 1 <= 10:
            led_bar.set(i + 1, led_bar.WHITE)  # ON
        time.sleep(0.1)
예제 #18
0
 def __init__(self, port=PORTB, nums=1):
     self.nums = nums * 3
     self.np = machine.Neopixel(Pin(port[0]), self.nums)
예제 #19
0
파일: M5GO.py 프로젝트: tebanski/M5GO
import machine
import units
import ujson as json
import utime as time
from utils import *
from m5stack import *
from mstate import *
import i2c_bus
# import _thread
# from M5GUI import *

VERSION = "0.2.2"
COLOR_GRAY = const(0xd7ceca)

# -------- Neopixel LED ---------
ledbar = machine.Neopixel(machine.Pin(15), 10)

# ------------- I2C -------------
# i2c = machine.I2C(sda=21, scl=22)
# units.i2c_used_0 = i2c
i2c = i2c_bus.get(i2c_bus.M_BUS)

# ------------ WLAN -------------
wlan_sta = network.WLAN(network.STA_IF)
wlan_sta.active(True)

# Define the WiFi events callback function


def wlan_evnet_cb(info):
    print("[WiFi] event: {} ({})".format(info[0], info[1]))
예제 #20
0
파일: tool.py 프로젝트: d4niele/my5stack
def clear_ledbar():
    ledbar = machine.Neopixel(machine.Pin(15), 10)
    ledbar.clear()
import uos, machine, time

np = machine.Neopixel(machine.Pin(5), 4)
np.set(0, 0xFF0000)
np.show()
import network
import gc

#connect
sta = network.WLAN(network.STA_IF)
sta.active(True)
wlan = list()
with open('credentials.txt', 'r') as f:
    # this file should contain ssid<space>pw, one per line
    line = f.readline().strip().split()
    while line:
        wlan.append(line)
        line = f.readline().strip().split()
if machine.wake_reason()[0] not in [4, 6]:  #Soft reset
    # this should help reconnecting... not sure whether it works or not
    # configuration below MUST match your home router settings!!
    print('configure wlan')
    sta.ifconfig(
        ('192.168.178.53', '255.255.255.0', '192.168.178.1', '8.8.8.8'))

timeout = 5000  #5 seconds
if not sta.isconnected():
    # try all wlans from the file
    # todo: scan first and check which can be seen
    for pw in wlan:
        start = time.ticks_ms()
예제 #22
0
 def __init__(self, np_pin=5, n=4):
     self.n = n
     self.np = machine.Neopixel(machine.Pin(np_pin), n)
     asyncio.get_event_loop().create_task(self.kitt())