OpenCores
URL https://opencores.org/ocsvn/neopixel_fpga/neopixel_fpga/trunk

Subversion Repositories neopixel_fpga

[/] [neopixel_fpga/] [trunk/] [src/] [strandtest/] [strandtest.ino] - Blame information for rev 3

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 splinedriv
/*
2
 *  FpgaNeoPixel - A spi to ws2812 machine
3
 *
4
 *  Modified for FpgaNeoPixel by Hirosh Dabui 
5
 *
6
 *  Permission to use, copy, modify, and/or distribute this software for any
7
 *  purpose with or without fee is hereby granted, provided that the above
8
 *  copyright notice and this permission notice appear in all copies.
9
 *
10
 *  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11
 *  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12
 *  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13
 *  ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14
 *  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15
 *  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16
 *  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17
 *
18
 */
19
 
20
// just overwrite show from Adafruit_NeoPixel to use it
21
// i have use strandtest.ino, just copy class FPGA_NeoPixel in your Adafruit_NeoPixel code
22
// and instantiate FPGA_NeoPixel
23
 
24
#define READY_PIN 49
25
#define RESETN_PIN 47
26
#define LED_PIN 6 // this pin is not needed
27
                  // but i don't wanted to touch Adafruit_NeoPixel code deeper
28
 
29
#include 
30
 
31
#define LED_COUNT 60
32
 
33
 
34
FPGA_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
35
 
36
// Argument 1 = Number of pixels in NeoPixel strip
37
// Argument 2 = Arduino pin number (most are valid)
38
// Argument 3 = Pixel type flags, add together as needed:
39
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
40
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
41
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
42
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
43
//   NEO_RGBW    Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
44
 
45
 
46
// setup() function -- runs once at startup --------------------------------
47
 
48
void setup() {
49
  // These lines are specifically to support the Adafruit Trinket 5V 16 MHz.
50
  // Any other board, you can remove this part (but no harm leaving it):
51
#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
52
  clock_prescale_set(clock_div_1);
53
#endif
54
  // END of Trinket-specific code.
55
 
56
  strip.begin();           // INITIALIZE NeoPixel strip object (REQUIRED)
57
  strip.show();            // Turn OFF all pixels ASAP
58
  strip.setBrightness(50); // Set BRIGHTNESS to about 1/5 (max = 255)
59
}
60
 
61
 
62
// loop() function -- runs repeatedly as long as board is on ---------------
63
 
64
void loop() {
65
#if 0
66
  // just set some pixel for testing
67
  strip.setPixelColor(0,255,0,0);
68
  strip.setPixelColor(59,0,0,255);
69
  strip.show();
70
  return;
71
#else
72
  // Fill along the length of the strip in various colors...
73
  colorWipe(strip.Color(255,   0,   0), 50); // Red
74
  colorWipe(strip.Color(  0, 255,   0), 50); // Green
75
  colorWipe(strip.Color(  0,   0, 255), 50); // Blue
76
 
77
  // Do a theater marquee effect in various colors...
78
  theaterChase(strip.Color(127, 127, 127), 50); // White, half brightness
79
  theaterChase(strip.Color(127,   0,   0), 50); // Red, half brightness
80
  theaterChase(strip.Color(  0,   0, 127), 50); // Blue, half brightness
81
 
82
  rainbow(10);             // Flowing rainbow cycle along the whole strip
83
  theaterChaseRainbow(50); // Rainbow-enhanced theaterChase variant
84
#endif
85
}
86
 
87
 
88
// Some functions of our own for creating animated effects -----------------
89
 
90
// Fill strip pixels one after another with a color. Strip is NOT cleared
91
// first; anything there will be covered pixel by pixel. Pass in color
92
// (as a single 'packed' 32-bit value, which you can get by calling
93
// strip.Color(red, green, blue) as shown in the loop() function above),
94
// and a delay time (in milliseconds) between pixels.
95
void colorWipe(uint32_t color, int wait) {
96
  for(int i=0; i
97
    strip.setPixelColor(i, color);         //  Set pixel's color (in RAM)
98
    strip.show();                          //  Update strip to match
99
    delay(wait);                           //  Pause for a moment
100
  }
101
}
102
 
103
// Theater-marquee-style chasing lights. Pass in a color (32-bit value,
104
// a la strip.Color(r,g,b) as mentioned above), and a delay time (in ms)
105
// between frames.
106
void theaterChase(uint32_t color, int wait) {
107
  for(int a=0; a<10; a++) {  // Repeat 10 times...
108
    for(int b=0; b<3; b++) { //  'b' counts from 0 to 2...
109
      strip.clear();         //   Set all pixels in RAM to 0 (off)
110
      // 'c' counts up from 'b' to end of strip in steps of 3...
111
      for(int c=b; c
112
        strip.setPixelColor(c, color); // Set pixel 'c' to value 'color'
113
      }
114
      strip.show(); // Update strip with new contents
115
      delay(wait);  // Pause for a moment
116
    }
117
  }
118
}
119
 
120
// Rainbow cycle along whole strip. Pass delay time (in ms) between frames.
121
void rainbow(int wait) {
122
  // Hue of first pixel runs 5 complete loops through the color wheel.
123
  // Color wheel has a range of 65536 but it's OK if we roll over, so
124
  // just count from 0 to 5*65536. Adding 256 to firstPixelHue each time
125
  // means we'll make 5*65536/256 = 1280 passes through this outer loop:
126
  for(long firstPixelHue = 0; firstPixelHue < 5*65536; firstPixelHue += 256) {
127
    for(int i=0; i
128
      // Offset pixel hue by an amount to make one full revolution of the
129
      // color wheel (range of 65536) along the length of the strip
130
      // (strip.numPixels() steps):
131
      int pixelHue = firstPixelHue + (i * 65536L / strip.numPixels());
132
      // strip.ColorHSV() can take 1 or 3 arguments: a hue (0 to 65535) or
133
      // optionally add saturation and value (brightness) (each 0 to 255).
134
      // Here we're using just the single-argument hue variant. The result
135
      // is passed through strip.gamma32() to provide 'truer' colors
136
      // before assigning to each pixel:
137
      strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue)));
138
    }
139
    strip.show(); // Update strip with new contents
140
    delay(wait);  // Pause for a moment
141
  }
142
}
143
 
144
// Rainbow-enhanced theater marquee. Pass delay time (in ms) between frames.
145
void theaterChaseRainbow(int wait) {
146
  int firstPixelHue = 0;     // First pixel starts at red (hue 0)
147
  for(int a=0; a<30; a++) {  // Repeat 30 times...
148
    for(int b=0; b<3; b++) { //  'b' counts from 0 to 2...
149
      strip.clear();         //   Set all pixels in RAM to 0 (off)
150
      // 'c' counts up from 'b' to end of strip in increments of 3...
151
      for(int c=b; c
152
        // hue of pixel 'c' is offset by an amount to make one full
153
        // revolution of the color wheel (range 65536) along the length
154
        // of the strip (strip.numPixels() steps):
155
        int      hue   = firstPixelHue + c * 65536L / strip.numPixels();
156
        uint32_t color = strip.gamma32(strip.ColorHSV(hue)); // hue -> RGB
157
        strip.setPixelColor(c, color); // Set pixel 'c' to value 'color'
158
      }
159
      strip.show();                // Update strip with new contents
160
      delay(wait);                 // Pause for a moment
161
      firstPixelHue += 65536 / 90; // One cycle of color wheel over 90 frames
162
    }
163
  }
164
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.