/* RGBlamp Get three byte from udp server to control Use TCP UDP RGB APP from play store to control lamp https://play.google.com/store/apps/details?id=nextprototypes.tcpudpRGB created 31 may 2015 by Mirco Segatello This code is in the public domain. */ /* 0 Verde 32 Giallo chiaro 64 Giallo scuro 96 Rosso 128 Fucsia 160 blu 192 azzurro 224 verde acqua */ #include "FastLED.h" #include #include char ssid[] = "WiFi8"; // your network SSID char pass[] = "mareblu123"; // your network password char packetBuffer[255]; unsigned int localPort = 8080; IPAddress serverIP(0, 0, 0, 0); // Broadcast communication WiFiUDP udp; // A UDP instance to send and receive packets over UDP //uncomment this line if using Debug message #define DEBUG // Number of leds in the strip #define NUM_LEDS 30 // Data pin that led data will be written out over #define DATA_PIN 6 // This is an array of leds. One item for each led in your strip. CRGB leds[NUM_LEDS]; CHSV Color; // Set initial color int R, G, B; // Set color for Huge function int R_H, G_H, B_H; //on powerUP RED light for search WiFi //if connect OK and IP assigned OK then Green light for 2 second void setup() { Serial.println(); Serial.begin(9600); FastLED.addLeds(leds, NUM_LEDS); // We start by connecting to a WiFi network Serial.print("Connecting to "); Serial.println(ssid); WiFi.begin(ssid, pass); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(); Serial.println("WiFi connected"); Serial.println("IP address: "); Serial.println(WiFi.localIP()); Serial.println("Starting UDP"); udp.begin(localPort); Serial.print("Local port: "); Serial.println(udp.localPort()); delay(2000); } void loop() { int packetSize = udp.parsePacket(); if (packetSize) { int len = udp.read(packetBuffer, 255); if (len > 0) packetBuffer[len] = 0;{ int R = packetBuffer[0]; int G = packetBuffer[1]; int B = packetBuffer[2]; R_H = R; G_H = G; B_H = B; #ifdef DEBUG Serial.println(packetBuffer); Serial.print(R); Serial.print(" "); Serial.print(G); Serial.print(" "); Serial.println(B); #endif FixLightRGB(G,R,B); #ifdef DEBUG Serial.println("sei ddentro Else"); #endif delay(100); } } #ifdef DEBUG Serial.println(packetBuffer); Serial.print(R_H); Serial.print(" "); Serial.print(G_H); Serial.print(" "); Serial.println(B_H); #endif if((R_H == 255) && (G_H == 113) && (B_H == 71)){ HugeSpan( 70, 86, 120); #ifdef DEBUG Serial.println("sei ddentro if HugeSpan"); #endif } } void HugeSpan( int LedSpeed, int InitialHuge, int FinalHuge){ for(int m = InitialHuge; m < FinalHuge; m = m + 1) { for(int whiteLed = 0; whiteLed < NUM_LEDS; whiteLed = whiteLed + 1) { // Turn all leds on to Color, then show the leds leds[whiteLed] = CHSV(m, 255,255); } FastLED.show(); delay (LedSpeed); } for(int m = FinalHuge; m > InitialHuge; m = m - 1) { for(int whiteLed = 0; whiteLed < NUM_LEDS; whiteLed = whiteLed + 1) { // Turn all leds on to Color, then show the leds leds[whiteLed] = CHSV(m, 255,255); } FastLED.show(); delay (LedSpeed); } } void FixLightRGB(int red, int green, int blue){ for(int i = 0; i < NUM_LEDS; i = i + 1) { // Turn all leds on to Color, then show the leds leds[i] = CRGB(red,green,blue); } FastLED.show(); }