/* This program contains all 20 possible combinations for a lane wich have an orientation. * The brightness of the color patterns is set here to 255. * Furthermore colors can be transmitted via rrr-ggg-bbb values. * It uses serial communication. */ #include #define LED_PIN 9 #define NUM_LEDS 29 String redString; String greenString; String blueString; String inputString; String color_pattern; Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, LED_PIN, NEO_GRB + NEO_KHZ800); /* Info: * set the color of a pixel: * strip.setPixelColor(n, red, green, blue); * pixel starts from n=0 * * Multiple pixels can be set to the same color using the fill() function, * which accepts one to three arguments. Typically it’s called like this: * strip.fill(color, first, count) */ int pause = 3000; // pause in ms // Definition of Colors int led_brightness = 255; uint32_t red = strip.Color(led_brightness,0,0); uint32_t green = strip.Color(0,led_brightness,0); uint32_t blue = strip.Color(0,0,led_brightness); uint32_t yellow = strip.Color(led_brightness,led_brightness,0); uint32_t magenta = strip.Color(led_brightness,0,led_brightness); uint32_t cyan = strip.Color(0,led_brightness,led_brightness); void setup() { // put your setup code here, to run once: Serial.begin(9600); strip.begin(); strip.clear(); strip.show(); // turn off all LEDs } void loop() { // put your main code here, to run repeatedly: if (Serial.available()) { inputString = Serial.readString(); color_pattern = inputString; Serial.print("Folgender Text wurde empfangen: "); Serial.println(inputString); //String aufteilen in R G B redString=inputString.substring(0,2+1); greenString=inputString.substring(4,6+1); blueString=inputString.substring(8,10+1); } // define color patterns if (color_pattern == "color_pattern_01") { SetColorCombination(red, green, blue); // color pattern 01 } else if (color_pattern == "color_pattern_02") { SetColorCombination(red, green, yellow); // color pattern 02 } else if (color_pattern == "color_pattern_03") { SetColorCombination(red, green, magenta); // color pattern 03 } else if (color_pattern == "color_pattern_04") { SetColorCombination(red, green, cyan); // color pattern 04 } else if (color_pattern == "color_pattern_05") { SetColorCombination(red, blue, yellow); // color pattern 05 } else if (color_pattern == "color_pattern_06") { SetColorCombination(red, blue, magenta); // color pattern 06 } else if (color_pattern == "color_pattern_07") { SetColorCombination(red, blue, cyan); // color pattern 07 } else if (color_pattern == "color_pattern_08") { SetColorCombination(red, yellow, magenta); // color pattern 08 } else if (color_pattern == "color_pattern_09") { SetColorCombination(red, yellow, cyan); // color pattern 09 } else if (color_pattern == "color_pattern_10") { SetColorCombination(red, magenta, cyan); // color pattern 10 } else if (color_pattern == "color_pattern_11") { SetColorCombination(green, blue, yellow); // color pattern 11 } else if (color_pattern == "color_pattern_12") { SetColorCombination(green, blue, magenta); // color pattern 12 } else if (color_pattern == "color_pattern_13") { SetColorCombination(green, blue, cyan); // color pattern 13 } else if (color_pattern == "color_pattern_14") { SetColorCombination(green, yellow, magenta); // color pattern 14 } else if (color_pattern == "color_pattern_15") { SetColorCombination(green, yellow, cyan); // color pattern 15 } else if (color_pattern == "color_pattern_16") { SetColorCombination(green, magenta, cyan); // color pattern 16 } else if (color_pattern == "color_pattern_17") { SetColorCombination(blue, yellow, magenta); // color pattern 17 } else if (color_pattern == "color_pattern_18") { SetColorCombination(blue, yellow, cyan); // color pattern 18 } else if (color_pattern == "color_pattern_19") { SetColorCombination(blue, magenta, cyan); // color pattern 19 } else if (color_pattern == "color_pattern_20") { SetColorCombination(yellow, magenta, cyan); // color pattern 20 } else{ strip.clear(); strip.fill(strip.Color(redString.toInt(),greenString.toInt(),blueString.toInt()),0,0); strip.show(); } } // Define Functions void SetColorCombination(uint32_t color_1, uint32_t color_2, uint32_t color_3){ // Set the color combination for the whole strip //determine whole numer of pixels, which can be displayed in a 3-row-constellation int number_of_3rowpixels = NUM_LEDS - (NUM_LEDS % 3); // should be 27 if 29 leds are mounted. Modulo = 2: (29 % 3)=(9x3) +2 int lastpixelindex = number_of_3rowpixels-1; // index starts at 0 for(int i=0; i<=lastpixelindex; i=i+3){ strip.setPixelColor(i, color_1); strip.setPixelColor(i+1, color_2); strip.setPixelColor(i+2, color_3); } strip.show(); }