Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <WiFi.h>
- #include <WiFiUdp.h>
- #include <FastLED.h>
- //set up WiFi
- const char* ssid = *****
- const char* password = ****
- const int localPort = 8888;
- WiFiUDP udp;
- //set up LEDs
- FASTLED_USING_NAMESPACE
- #define DATA_PIN 13
- //#define CLK_PIN 4
- #define LED_TYPE WS2812B
- #define COLOR_ORDER GRB
- #define NUM_LEDS 144
- CRGB leds[NUM_LEDS];
- #define BRIGHTNESS 255
- #define FRAMES_PER_SECOND 120
- //received potentiometer inputs from WiFi connection
- int inputs[4];
- int paletteIndex = 0;
- CRGBPalette256 currentPalette;
- TBlendType currentBlending;
- void setup() {
- //set up LEDs
- FastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
- // set master brightness control
- FastLED.setBrightness(BRIGHTNESS);
- currentPalette = LavaColors_p;
- delay(2000);
- Serial.begin(115200);
- delay(10);
- // Connect to Wi-Fi
- Serial.println();
- Serial.print("Connecting to ");
- Serial.println(ssid);
- WiFi.begin(ssid, password);
- while (WiFi.status() != WL_CONNECTED) {
- delay(500);
- Serial.print(".");
- }
- Serial.println("WiFi connected");
- // Start UDP
- udp.begin(localPort);
- }
- void loop() {
- receiver();
- fill_palette(leds,NUM_LEDS,paletteIndex,255/NUM_LEDS,currentPalette,255,LINEARBLEND);
- fadeToBlackBy(leds,NUM_LEDS,1);
- paletteChooser(inputs[0]);
- EVERY_N_MILLISECONDS(10){
- paletteIndex += inputs[1];
- }
- // send the 'leds' array out to the actual LED strip
- FastLED.show();
- // insert a delay to keep the framerate modest
- FastLED.delay(1000/FRAMES_PER_SECOND);
- }
- void paletteChooser(int j){
- if (j == 0){
- currentPalette = OceanColors_p;
- currentBlending = LINEARBLEND;
- }
- if (j == 1){
- currentPalette = LavaColors_p;
- currentBlending = LINEARBLEND;
- }
- if (j == 2){
- currentPalette = CloudColors_p;
- currentBlending = LINEARBLEND;
- }
- if (j = 3){
- currentPalette = ForestColors_p;
- currentBlending = LINEARBLEND;
- }
- }
- void receiver(){
- int packetSize = udp.parsePacket();
- if (packetSize) {
- // Allocate buffer for incoming packet
- char incomingPacket[255];
- udp.read(incomingPacket, packetSize);
- incomingPacket[packetSize] = '\0';
- // Parse the received string back into an array of integers
- char *token = strtok(incomingPacket, ",");
- for (int i = 0; i < 4; i++) {
- inputs[i] = atoi(token);
- token = strtok(NULL, ",");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment