//Based on the Neopixel Strandtest //Edited by Micky van Zeijl - 13 May 2019 //Include the Neopixel and serial library #include #include //Define the pins for serial communication #define rxPin 0 #define txPin 1 //This part is in the example which is required for 16 MHz Adafruit Trinket #ifdef __AVR__ #include #endif //Define the pin for the LED and strip and define how many NeoPixels are attached to Neopixel board #define LED_PIN 2 #define LED_COUNT 1 //set an integer for serial communication and use this to change modes. int incomingByte = 0; //Declare serial communication and declare the Neopixel strip object SoftwareSerial serial(rxPin, txPin); Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800); //For the Neopixel strip: //Argument 1 = number of pixel in strip //Argument 2 = pinnumber of ATtiny connected to Neopixel strip //Argument 3 = NEO_GRB pixels are wired for GRB bitstream and with NEO_KHZ800, which means 800KHz bitstream //The setup function runs once at startup ----------------------------------- void setup() { // These lines are specifically to support the Adafruit Trinket 5V 16 MHz. // Any other board, you can remove this part (but no harm leaving it): #if defined(__AVR_ATtiny85__) && (F_CPU == 16000000) clock_prescale_set(clock_div_1); #endif // END of Trinket-specific code. //This is the setup of pinmodes and start serial communication pinMode(rxPin, INPUT); pinMode(txPin, OUTPUT); serial.begin(9600); //General setup for Neopixel strip object. Begin()initializes the object, show() turns off all pixels //setBrightness(50) sets the Brightness to about 1/5 (max = 255) strip.begin(); strip.show(); strip.setBrightness(50); } //The loop function -- runs repeatedly as long as board is on -------------------------- void loop() { //set the integer to the serial communication incomingByte = serial.read(); //if serial communication sends a 1 it will turn the leds to green if (incomingByte == '1') { colorWipe(strip.Color(255, 0, 0), 50); delay (2000); colorWipe(strip.Color(0, 0, 0), 0); delay (2000); } //if serial communication sends a 2 it will turn red else if (incomingByte == '2') { colorWipe(strip.Color(0, 255, 0), 50); delay (2000); colorWipe(strip.Color(0, 0, 0), 0); // off delay (2000); } //if serial communication sends a 3 it will turns blue else if (incomingByte == '3') { colorWipe(strip.Color(0, 0, 255), 50); delay (2000); colorWipe(strip.Color(0, 0, 0), 0); // off delay (2000); } //if serial communication sends a 4 it will turns to white else if (incomingByte == '4') { colorWipe(strip.Color(255, 255, 255), 50); delay (2000); colorWipe(strip.Color(0, 0, 0), 0); // off delay (2000); } } //colorWipe is a helper function. It's defined liked this in the strandtest example. ----- //For each pixel in the strip it sets the pixel's color (inRAM), it updates the strip to match with the colors with .show() //It pauses for a moment with delay(wait) void colorWipe(uint32_t color, int wait) { for (int i = 0; i < strip.numPixels(); i++) { strip.setPixelColor(i, color); strip.show(); delay(wait); } }