github.com/robgonnella/ardi/v2@v2.4.5-0.20230102052001-11a49de978c3/test_projects/pixie/pixie.ino (about)

     1  /*
     2    Pixie reads data in at 115.2k serial, 8N1.
     3    Byte order is R1, G1, B1, R2, G2, B2, ... where the first triplet is the
     4    color of the LED that's closest to the controller. 1ms of silence triggers
     5    latch. 2 seconds silence (or overheating) triggers LED off (for safety).
     6  
     7    Do not look into Pixie with remaining eye!
     8  */
     9  
    10  #include "SoftwareSerial.h"
    11  #include "Adafruit_Pixie.h"
    12  
    13  #define NUMPIXELS 3 // Number of Pixies in the strip
    14  #define PIXIEPIN 6  // Pin number for SoftwareSerial output
    15  
    16  SoftwareSerial pixieSerial(-1, PIXIEPIN);
    17  
    18  Adafruit_Pixie strip = Adafruit_Pixie(NUMPIXELS, &pixieSerial);
    19  // Alternately, can use a hardware serial port for output, e.g.:
    20  // Adafruit_Pixie strip = Adafruit_Pixie(NUMPIXELS, &Serial1);
    21  
    22  void setup()
    23  {
    24    int i;
    25  
    26    Serial.begin(9600);
    27    Serial.println("Ready to Pixie");
    28  
    29    pixieSerial.begin(115200); // Pixie REQUIRES this baud rate
    30    // Serial1.begin(115200);  // <- Alt. if using hardware serial port
    31  
    32    strip.setBrightness(200); // Adjust as necessary to avoid blinding
    33  
    34    Serial.println("Red");
    35    for (i = 0; i < NUMPIXELS; i++)
    36      strip.setPixelColor(i, 255, 0, 0);
    37    strip.show();
    38    delay(300);
    39  
    40    Serial.println("Green");
    41    for (i = 0; i < NUMPIXELS; i++)
    42      strip.setPixelColor(i, 0, 255, 0);
    43    strip.show();
    44    delay(300);
    45  
    46    Serial.println("Blue");
    47    for (i = 0; i < NUMPIXELS; i++)
    48      strip.setPixelColor(i, 0, 0, 255);
    49    strip.show();
    50    delay(300);
    51  }
    52  
    53  void loop()
    54  {
    55    Serial.println("Rainbow");
    56    rainbowCycle(10);
    57  }
    58  
    59  // Slightly different, this makes the rainbow equally distributed throughout
    60  void rainbowCycle(uint8_t wait)
    61  {
    62    uint16_t i, j;
    63  
    64    for (j = 0; j < 256 * 5; j++)
    65    { // 5 cycles of all colors on wheel
    66      for (i = 0; i < NUMPIXELS; i++)
    67      {
    68        strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
    69      }
    70      strip.show();
    71      delay(wait);
    72    }
    73  }
    74  
    75  // Input a value 0 to 255 to get a color value.
    76  // The colours are a transition r - g - b - back to r.
    77  uint32_t Wheel(byte WheelPos)
    78  {
    79    if (WheelPos < 85)
    80    {
    81      return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
    82    }
    83    else if (WheelPos < 170)
    84    {
    85      WheelPos -= 85;
    86      return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
    87    }
    88    else
    89    {
    90      WheelPos -= 170;
    91      return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
    92    }
    93  }