def loop(): global index next_column_time = 0 while True: esp.apa102_write(clock, data, mv[index:index + 200]) sleep_us(ticks_diff(next_column_time, ticks_us())) next_column_time = ticks_add(ticks_us(), segment_duration) index += 50
def change(): for j in range(100): for i in range(32): raw.readinto(buf) esp.apa102_write(clock, data, buf) #time.sleep_us(500000) while hall.value(): True raw.seek(0)
def vsync(_): micropython.schedule(recalc, ticks_us()) hall.irq(vsync, trigger=Pin.IRQ_FALLING) #, wake=IDLE | SLEEP | DEEPSLEEP) buf = bytearray(6400) raw = open("pictures/colorPye.bytes", "rb") raw.readinto(buf) raw.close() mv = memoryview(buf) buf2 = bytearray(52 * 4) def loop(): global index next_column_time = 0 while True: esp.apa102_write(clock, data, mv[index:index + 200]) sleep_us(ticks_diff(next_column_time, ticks_us())) next_column_time = ticks_add(ticks_us(), segment_duration) index += 50 esp.apa102_write(clock, data, buf2) led.value(1) loop() esp.apa102_write(clock, data, buf2) led.value(0) print("chau pycamp")
def write(self): apa102_write(self.clock_pin, self.pin, self.buf)
def nextframe(*args): raw.readinto(buf) esp.apa102_write(clock, data, buf)
def write(self): apa102_write(self.clock_pin, self.pin, self.buf)
# APA102 driver # Use the apa102 module: from machine import Pin from apa102 import APA102 clock = Pin(14, Pin.OUT) # set GPIO14 to output to drive the clock data = Pin(13, Pin.OUT) # set GPIO13 to output to drive the data apa = APA102(clock, data, 8) # create APA102 driver on the clock and the data pin for 8 pixels apa[0] = (255, 255, 255, 31) # set the first pixel to white with a maximum brightness of 31 apa.write() # write data to all pixels r, g, b, brightness = apa[0] # get first pixel colour For low-level driving of an APA102: import esp esp.apa102_write(clock_pin, data_pin, rgbi_buf) # _________________________________________________________ # DHT driver # The DHT driver is implemented in software and works on all pins: # \1\0 import dht import machine d = dht.DHT11(machine.Pin(4)) d.measure() d.temperature() # eg. 23 (°C) d.humidity() # eg. 41 (% RH)
def recalc(this_turn): esp.apa102_write(clock, data, buf) change()