晶片接腳介紹
伺服馬達接線圖
開啟內建電路程式碼
設定
設定
至裝置管理員查看伺服馬達接至哪個序列埠
設定
亮滅
#include <Adafruit_NeoPixel.h>
#define PIN 2
#define NUMPIXELS 24
Adafruit_NeoPixel strip(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
strip.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
strip.setPixelColor(0, strip.Color(50, 0, 0));
strip.setPixelColor(1, strip.Color(0, 250, 0));
strip.show();
}
void loop() {
AllLedColor(0, 0, 0);
delay(1000);
LedFromToColor(0, NUMPIXELS, 50, 0, 250);
delay(1000);
}
//---------------------------------------------------------------------
void AllLedColor(byte red, byte green, byte blue) {
LedFromToColor(0, NUMPIXELS, red, green, blue);
}
void LedFromToColor(byte from, byte len, byte red, byte green, byte blue) {
for (int i = from; i < from + len; i++) {
strip.setPixelColor(i, strip.Color(red, green, blue));
}
strip.show();
}
右旋
#include <SimpleTimer.h>
SimpleTimer ABC;
#include <Adafruit_NeoPixel.h>
#define PIN 2
#define NUMPIXELS 24
Adafruit_NeoPixel strip(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
void RightRotate() {
int static count = 24;
count = count - 1;
if (count < 1)count = 24;
Serial.print("RightRotate=");
Serial.println(count);
AllLedColor(0, 0, 0);
LedFromToColor(count, 1, 0, 250, 20);
}
void setup() {
strip.begin();
Serial.begin(9600);
ABC.setInterval(50, RightRotate);
}
void loop () {
ABC.run();
}
//---------------------------------------------------------------------
void AllLedColor(byte red, byte green, byte blue) {
LedFromToColor(0, NUMPIXELS, red, green, blue);
}
void LedFromToColor(byte from, byte len, byte red, byte green, byte blue) {
for (int i = from; i < from + len; i++) {
strip.setPixelColor(i, strip.Color(red, green, blue));
}
strip.show();
}
由左至右亮.由左至右滅(自訂)
#include <Adafruit_NeoPixel.h>
#ifdef _AVR_
#include <avr/power.h>
#endif
// Which pin on the Arduino is connected to the NeoPixels?
// On a Trinket or Gemma we suggest changing this to 1
#define PIN 2
// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS 21
// When we setup the NeoPixel library, we tell it how many pixels, and which pin to use to send signals.
// Note that for older NeoPixel strips you might need to change the third parameter--see the strandtest
// example for more information on possible values.
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
int delayval = 500; // delay for half a second
void setup() {
// This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
#if defined (_AVR_ATtiny85_)
if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
#endif
// End of trinket special code
pixels.begin(); // This initializes the NeoPixel library.
}
void loop() {
delay(2000);
// For a set of NeoPixels the first NeoPixel is 0, second is 1, all the way up to the count of pixels minus one.
for (int i = 0; i < NUMPIXELS; i++) {
// pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
pixels.setPixelColor(i, pixels.Color(200, 80, 200)); // Moderately bright green color.
pixels.show(); // This sends the updated pixel color to the hardware.
delay(delayval); // Delay for a period of time (in milliseconds).
}
for (int i = 0; i < NUMPIXELS; i++) {
// pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
pixels.setPixelColor(i, pixels.Color(0, 0, 0)); // Moderately bright green color.
pixels.show(); // This sends the updated pixel color to the hardware.
delay(delayval); // Delay for a period of time (in milliseconds).
}
for (int i = 0; i < NUMPIXELS; i++) {
// pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
pixels.setPixelColor(i, pixels.Color(200,250, 0)); // Moderately bright green color.
pixels.show(); // This sends the updated pixel color to the hardware.
delay(delayval); // Delay for a period of time (in milliseconds).
}
for (int i = 0; i < NUMPIXELS; i++) {
// pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
pixels.setPixelColor(i, pixels.Color(0, 0, 0)); // Moderately bright green color.
pixels.show(); // This sends the updated pixel color to the hardware.
delay(delayval); // Delay for a period of time (in milliseconds).
}
for (int i = 0; i < NUMPIXELS; i++) {
// pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
pixels.setPixelColor(i, pixels.Color(0, 0, 20)); // Moderately bright green color.
pixels.show(); // This sends the updated pixel color to the hardware.
delay(delayval); // Delay for a period of time (in milliseconds).
}
for (int i = 0; i < NUMPIXELS; i++) {
// pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
pixels.setPixelColor(i, pixels.Color(0, 0, 0)); // Moderately bright green color.
pixels.show(); // This sends the updated pixel color to the hardware.
delay(delayval); // Delay for a period of time (in milliseconds).
}
}
左旋
#include <SimpleTimer.h>
SimpleTimer ABC;
#include <Adafruit_NeoPixel.h>
#define PIN 2
#define NUMPIXELS 24
Adafruit_NeoPixel strip(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
void LeftRotate() {
int static count = 0;
count = count + 1;
if (count > 23)count = 0;
Serial.print("LeftRotate=");
Serial.println(count);
AllLedColor(0, 0, 0);
LedFromToColor(count, 1, 50, 200, 180);
}
void setup() {
strip.begin();
Serial.begin(9600);
ABC.setInterval(100, LeftRotate);
}
void loop () {
ABC.run();
}
//---------------------------------------------------------------------
void AllLedColor(byte red, byte green, byte blue) {
LedFromToColor(0, NUMPIXELS, red, green, blue);
}
void LedFromToColor(byte from, byte len, byte red, byte green, byte blue) {
for (int i = from; i < from + len; i++) {
strip.setPixelColor(i, strip.Color(red, green, blue));
}
strip.show();
}
霹靂燈
#include <SimpleTimer.h>
SimpleTimer ABC;
#include <Adafruit_NeoPixel.h>
#define PIN 2
#define NUMPIXELS 12
Adafruit_NeoPixel strip(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
void pili() {
int static count = 0;
count = count + 1;
if (count > 12)count = 0;
Serial.print("pili=");
Serial.println(count);
AllLedColor(0, 0, 0);
LedFromToColor(count, 1,120, 0, 80);
LedFromToColor(NUMPIXELS - 2 - count, 1, 120, 0, 80);
}
void setup() {
strip.begin();
Serial.begin(9600);
ABC.setInterval(100, pili);
}
void loop () {
ABC.run();
}
//---------------------------------------------------------------------
void AllLedColor(byte red, byte green, byte blue) {
LedFromToColor(0, NUMPIXELS, red, green, blue);
}
void LedFromToColor(byte from, byte len, byte red, byte green, byte blue) {
for (int i = from; i < from + len; i++) {
strip.setPixelColor(i, strip.Color(red, green, blue));
}
strip.show();
}