#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h> // Required for 16 MHz Adafruit Trinket
#endif


#define LED_PIN    15
#define LED_COUNT 24


Adafruit_NeoPixel pixels(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);


void setup() {
#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
  clock_prescale_set(clock_div_1);
#endif
  // END of Trinket-specific code.

  pixels.begin();           // INITIALIZE NeoPixel pixels object (REQUIRED)
  pixels.show();            // Turn OFF all pixels ASAP
  pixels.setBrightness(255); // Set BRIGHTNESS to about 1/5 (max = 255)
}


// loop() function -- runs repeatedly as long as board is on ---------------



//------------สีวน รุ้ง ม่วง คราม น้ำเงิน เขียว เหลือง แสด แดง --------------------------


  void loop()
{
  colorWipe(pixels.Color(255,   51,   153), 50); // ม่วงแดง
  colorWipe(pixels.Color(255,   51,   255), 50); // ม่วงชม
  colorWipe(pixels.Color(  153,   51, 255), 50); // ม่วง
  colorWipe(pixels.Color(51,   51,   255), 50); // คราม
  colorWipe(pixels.Color(  51, 153,   255), 50); // น้ำเงิน
  colorWipe(pixels.Color(  51,   255, 255), 50); // ฟ้า
  colorWipe(pixels.Color(  51,   255, 153), 50); // เขียวฟ้า
  colorWipe(pixels.Color(  51,   255, 51), 50); // เขียว
  colorWipe(pixels.Color(  153,   255, 51), 50); // เขียวเหลือง
  colorWipe(pixels.Color(  255,   255, 51), 50); // เหลือง
  colorWipe(pixels.Color(  255,   153, 51), 50); // ส้ม
  colorWipe(pixels.Color(  255,   51, 51), 50); // แดง
  
}

void colorWipe(uint32_t color, int wait) {
  for(int i=0; i<pixels.numPixels(); i++) { // For each pixel in pixels...
    pixels.setPixelColor(i, color);         //  Set pixel's color (in RAM)
    pixels.show();                          //  Update pixels to match
    delay(wait);                           //  Pause for a moment
  }
}



//------------สีวน รุ้ง ม่วง คราม น้ำเงิน เขียว เหลือง แสด แดง --------------------------











//-------------------------- Rainbow --------------------------

// void loop() {
//   rainbow(10);             // Flowing rainbow cycle along the whole pixels
//   theaterChaseRainbow(50); // Rainbow-enhanced theaterChase variant
// }

// void colorWipe(uint32_t color, int wait) {
//   for(int i=0; i<pixels.numPixels(); i++) { // For each pixel in pixels...
//     pixels.setPixelColor(i, color);         //  Set pixel's color (in RAM)
//     pixels.show();                          //  Update pixels to match
//     delay(wait);                           //  Pause for a moment
//   }
// }

// void theaterChase(uint32_t color, int wait) {
//   for(int a=0; a<10; a++) {  // Repeat 10 times...
//     for(int b=0; b<3; b++) { //  'b' counts from 0 to 2...
//       pixels.clear();         //   Set all pixels in RAM to 0 (off)
//       // 'c' counts up from 'b' to end of pixels in steps of 3...
//       for(int c=b; c<pixels.numPixels(); c += 3) {
//         pixels.setPixelColor(c, color); // Set pixel 'c' to value 'color'
//       }
//       pixels.show(); // Update pixels with new contents
//       delay(wait);  // Pause for a moment
//     }
//   }
// }

// void rainbow(int wait) {
//   for(long firstPixelHue = 0; firstPixelHue < 5*65536; firstPixelHue += 256) {
//     pixels.rainbow(firstPixelHue);
//     pixels.show(); // Update pixels with new contents
//     delay(wait);  // Pause for a moment
//   }
// }

// void theaterChaseRainbow(int wait) {
//   int firstPixelHue = 0;     // First pixel starts at red (hue 0)
//   for(int a=0; a<30; a++) {  // Repeat 30 times...
//     for(int b=0; b<3; b++) { //  'b' counts from 0 to 2...
//       pixels.clear();         //   Set all pixels in RAM to 0 (off)
//       for(int c=b; c<pixels.numPixels(); c += 3) {
//         int      hue   = firstPixelHue + c * 65536L / pixels.numPixels();
//         uint32_t color = pixels.gamma32(pixels.ColorHSV(hue)); // hue -> RGB
//         pixels.setPixelColor(c, color); // Set pixel 'c' to value 'color'
//       }
//       pixels.show();                // Update pixels with new contents
//       delay(wait);                 // Pause for a moment
//       firstPixelHue += 65536 / 90; // One cycle of color wheel over 90 frames
//     }
//   }
// }


//-------------------------- Rainbow --------------------------



//-------------------------- Loading_ledloop Cyan --------------------------

// int offset;                         // the position of the red leds, 0...7

// // A table with the values.
// // Keep the size below 8.
// // The leds turn right and the ledIndex is incremented,
// // therefor the front led is the last one in the table.
// const int sizeTable = 6;
// const int table[] = { 220, 150, 0, 0, 150, 220};   // soft blob
// //const int table[] = { 100, 180, 255, 255, 180, 100};   // soft blob
// // const int table[] = { 80, 100, 120, 160, 200, 255};   // only a trail

// void loop()
// {
//   pixels.clear();                           // all leds off

//   // lay the table on the leds, according to the position
//   for ( int i = 0; i < sizeTable; i++)      // walk along the table
//   {
//     int ledIndex = offset + i;
//     ledIndex = ledIndex % 8;                // clip the ledIndex to 0...7

//     // Set left ring
//     // The table is put twice on the leds.
//     pixels.setPixelColor( ledIndex, pixels.Color( table[i], 255,230 ));
//     pixels.setPixelColor( ledIndex + 8, pixels.Color(table[i], 255, 230));

//     // Set right ring
//     // The table is put twice on the leds.
//     pixels.setPixelColor( ledIndex + 16, pixels.Color( table[i], 255, 230));
//     pixels.setPixelColor( ledIndex + 24, pixels.Color( table[i], 255, 230));
//   }

//   pixels.show();        // update the new values to the ledpixels

//   offset++;
//   if ( offset >= 8)
//     offset = 0;

//   delay( 100);
// }

//-------------------------- Loading_ledloop Cyan --------------------------






//-------------------------- กระพริบ --------------------------
//กระพริบ
// void loop() {
//    pixels.fill(pixels.Color(255, 0, 0));
//     pixels.show();
//     delay(100);
//     pixels.fill(pixels.Color(0, 0, 0));
//     pixels.show();
//     delay(100);
//   }

//-------------------------- กระพริบ --------------------------