Modifications

Sauter à la navigation Sauter à la recherche
4 599 octets ajoutés ,  24 février 2014 à 14:33
Ligne 29 : Ligne 29 :     
{{ADFImage|NeoPixel-UserGuide-Arduino-Brancher-01.png|640px}}
 
{{ADFImage|NeoPixel-UserGuide-Arduino-Brancher-01.png|640px}}
 +
 +
{{ambox-stop|text=When connecting NeoPixels to any live power source or microcontroller, ALWAYS CONNECT GROUND (–) BEFORE ANYTHING ELSE. Conversely, disconnect ground last when separating.}}
 +
 +
 +
{{ambox-stop|text=Adding a ~470 ohm resistor between your microcontroller's data pin and the data input on the NeoPixels can help prevent spikes on the data line that can damage your first pixel. Please add one between your micro and NeoPixels!}}
 +
 +
 +
{{ambox-stop|text= We also recommend adding a large capacitor (1000 µF, 6.3V or higher) across the + and – terminals. This prevents the initial onrush of current from damaging the pixels. See the photo on the next page for an example.}}
 +
 +
=== Can NeoPixels be powered directly from the Arduino’s 5V pin? ==
 +
 +
Sometimes. The Arduino can continuously supply only about 500 milliamps to the 5V pin. Each NeoPixel can draw up to 60 milliamps at full brightness. So yes, you can skip the separate DC supply and power directly off the Arduino as long as just a few pixels are used, or more if the colors and overall brightness are low. When in doubt, give the pixels a separate power supply.
 +
 +
== Code d'exemple simple: standtest ==
 +
 +
Launch the Arduino IDE. From the File menu, select '''Fichier > Exemple > Adafruit_NeoPixel > strandtest'''
 +
 +
(If the Adafruit_NeoPixel rollover menu is not present, the library has not been correctly installed, or the IDE needs to be restarted after installation. Check the installation steps above to confirm it’s properly named and located.)
 +
 +
Select your board type and serial port from the Tools menu, and try uploading to the board. If the NeoPixels are connected and powered, you should see a little light show.
 +
 +
=== Il ne se passe rien ===
 +
 +
Check your connections. The most common mistake is connecting to the output end of a strip rather than the input.
 +
 +
=== Inspectons le code ===
 +
 +
Let’s look at the code now...
 +
 +
All NeoPixel sketches begin by including the header file:
 +
 +
<nowiki>#include <Adafruit_NeoPixel.h></nowiki>
 +
 +
The block of code that follows is mostly descriptive comments. Only the last line is really doing any work:
 +
 +
<nowiki>#define PIN 6
 +
 +
// Parameter 1 = number of pixels in strip
 +
// Parameter 2 = pin number (most are valid)
 +
// Parameter 3 = pixel type flags, add together as needed:
 +
//  NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
 +
//  NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
 +
//  NEO_GRB    Pixels are wired for GRB bitstream (most NeoPixel products)
 +
//  NEO_RGB    Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
 +
Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PIN, NEO_GRB + NEO_KHZ800);</nowiki>
 +
 +
The first line assigns a number to the symbol “PIN” for later reference. It doesn’t ''need'' to be done this way, but makes it easier to change the pin where the NeoPixels are connected without digging deeper into the code.
 +
 +
The last line declares a NeoPixel ''object''. We’ll refer to this by name later to control the strip of pixels. There are three parameters or arguments in parenthesis:
 +
# The number of sequential NeoPixels in the strip. In the example this is set to 60, equal to 1 meter of medium-density strip. Change this to match the actual number you’re using.
 +
# The pin number to which the NeoPixel strip (or other device) is connected. Normally this would be a number, but we previously declared the symbol PIN to refer to it by name here.
 +
# A value indicating the type of NeoPixels that are connected. '''In most cases you can leave this off and pass just two arguments'''; the example code is just being extra descriptive. If you have a supply of classic “V1” Flora pixels, those require NEO_KHZ400 + NEO_RGB to be passed here.
 +
 +
Then, in the setup() function, call begin() to prepare the data pin for NeoPixel output:
 +
 +
<nowiki>void setup() {
 +
  strip.begin();
 +
  strip.show(); // Initialize all pixels to 'off'
 +
}</nowiki>
 +
 +
The second line, strip.show(), isn’t absolutely necessary, it’s just there to be thorough. That function pushes data out to the pixels…since no colors have been set yet, this initializes all the NeoPixels to an initial “off” state in case some were left lit by a prior program.
 +
In the strandtest example, loop() doesn’t set any pixel colors on its own — it calls other functions that create animated effects. So let’s ignore it for now and look ahead, inside the individual functions, to see how the strip is controlled.
 +
 +
There are two ways to set the color of a pixel. The first is:
 +
 +
<nowiki>strip.setPixelColor(n, red, green, blue);</nowiki>
 +
    
{{NeoPixel-UserGuide-TRAILER}}
 
{{NeoPixel-UserGuide-TRAILER}}
29 917

modifications

Menu de navigation