Last active
August 10, 2024 10:59
-
-
Save jensjeflensje/fcf3a07775f6a1659a889e331892528a to your computer and use it in GitHub Desktop.
Code voor mijn tiktok live led strip | https://www.youtube.com/watch?v=fdICoCZvp-U
This file contains 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
#include <Adafruit_NeoPixel.h> | |
#define PIN_NEO_PIXEL 10 // Arduino pin that connects to NeoPixel | |
#define NUM_PIXELS 144 // The number of LEDs (pixels) on NeoPixel | |
Adafruit_NeoPixel NeoPixel(NUM_PIXELS, PIN_NEO_PIXEL, NEO_GRBW + NEO_KHZ800); | |
String inString = ""; | |
int color; | |
void setup() { | |
NeoPixel.begin(); | |
NeoPixel.setBrightness(60); // fel genoeg | |
NeoPixel.clear(); | |
Serial.begin(115200); | |
while (!Serial) { | |
; | |
} | |
} | |
void loop() { | |
while (!Serial.available()); | |
int inChar = Serial.read(); | |
if (isDigit(inChar)) { | |
inString += (char)inChar; | |
} else if (inChar == '\n') { | |
color = inString.toInt(); | |
NeoPixel.clear(); | |
NeoPixel.fill(NeoPixel.gamma32(NeoPixel.ColorHSV(color))); | |
NeoPixel.show(); | |
inString = ""; | |
} | |
delay(10); | |
} |
This file contains 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 serial | |
import time | |
from TikTokLive import TikTokLiveClient | |
from TikTokLive.events import CommentEvent, ConnectEvent, LikeEvent | |
# specifiek aan mijn computer (zelfde als in arduino IDE staat) | |
ser = serial.Serial("/dev/cu.usbmodem212301", 115200, timeout=0.1) | |
# eigen username invullen (of course) | |
client: TikTokLiveClient = TikTokLiveClient(unique_id="jensderouter") | |
accepted_colors = { | |
"rood": "0", | |
"ginger": "5000", | |
"oranje": "6000", | |
"geel": "10000", | |
"groen": "20000", | |
"lichtgroen": "25000", | |
"lichtblauw": "30000", | |
"blauw": "40000", | |
"paars": "52000", | |
"roze": "56000", | |
} | |
def write_to_ser(message: str): | |
ser.write(str(message + '\n').encode()) | |
time.sleep(0.01) | |
def process_comment(message: str): | |
color = accepted_colors.get(message.lower()) | |
if color: | |
write_to_ser(color) | |
@client.on(CommentEvent) | |
async def on_comment(event: CommentEvent): | |
process_comment(event.comment) | |
@client.on(ConnectEvent) | |
async def on_connect(_: ConnectEvent): | |
print("Connected to Room ID:", client.room_id) | |
if __name__ == '__main__': | |
try: | |
client.run() | |
except KeyboardInterrupt: | |
ser.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment