This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import uasyncio as asyncio | |
from machine import I2S, Pin | |
# I2S configuration | |
device_config = { | |
'bck': 19, | |
'ws': 33, | |
'sdout': 22, | |
} | |
SAMPLES_PER_SECOND = 16000 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Simple script to start white noise on button click on rpi zero w2 combined with waveshare WM8960 audio hat | |
# It will also stop/start an airplay container | |
import RPi.GPIO as GPIO | |
import pygame | |
import time | |
import subprocess | |
# Initialize pygame mixer | |
pygame.mixer.init() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def color_map(N=256, normalized=True): | |
def bitget(byteval, idx): | |
return (byteval & (1 << idx)) != 0 | |
dtype = 'float32' if normalized else 'uint8' | |
cmap = np.zeros((N, 3), dtype=dtype) | |
for i in range(N): | |
r = g = b = 0 | |
c = i | |
for j in range(8): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def my_atan2(y, x): | |
pi = torch.from_numpy(np.array([np.pi])).to(y.device, y.dtype) | |
ans = torch.atan(y / (x + 1e-6)) | |
ans += ((y > 0) & (x < 0)) * pi | |
ans -= ((y < 0) & (x < 0)) * pi | |
ans *= (1 - ((y > 0) & (x == 0)) * 1.0) | |
ans += ((y > 0) & (x == 0)) * (pi / 2) | |
ans *= (1 - ((y < 0) & (x == 0)) * 1.0) | |
ans += ((y < 0) & (x == 0)) * (-pi / 2) | |
return ans |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from time import sleep | |
import gym | |
import numpy as np | |
import matplotlib.pyplot as plt | |
import sys | |
import os | |
def val_to_bin(obs): |