本文整理汇总了C++中Adafruit_NeoPixel类的典型用法代码示例。如果您正苦于以下问题:C++ Adafruit_NeoPixel类的具体用法?C++ Adafruit_NeoPixel怎么用?C++ Adafruit_NeoPixel使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Adafruit_NeoPixel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: lightUp
void lightUp() {
if (++colorIndex == NUM_COLORS) {
colorIndex = 0;
}
int red = colorList[colorIndex][0];
int green = colorList[colorIndex][1];
int blue = colorList[colorIndex][2];
// Bounds detection
if (currentPixel == 0) {
direction = 1;
} else if (currentPixel == NUM_PIXELS) {
direction = -1;
}
// Advancing the pixel
currentPixel = currentPixel + (1 * direction);
// now we will 'fade' it in 5 steps
for (int x = 0; x < 5; x++) {
int r = red * (x+1); r /= 5;
int g = green * (x+1); g /= 5;
int b = blue * (x+1); b /= 5;
strip.setPixelColor(currentPixel, strip.Color(r, g, b));
strip.show();
delay(BLINK_DELAY);
}
// & fade out in 5 steps
for (int x = 5; x >= 0; x--) {
int r = red * x; r /= 5;
int g = green * x; g /= 5;
int b = blue * x; b /= 5;
strip.setPixelColor(currentPixel, strip.Color(r, g, b));
strip.show();
delay(BLINK_DELAY);
}
}
示例2: init_leds
inline void init_leds(){
top_panels.begin();
bottom_panels.begin();
unsigned long int color = bottom_panels.Color(50, 0, 0 );
set_all_leds(color);
}
示例3: setupPins
void ExtendoHand::setupPins() {
pinMode(VIBRO_PIN, OUTPUT);
leds.begin();
}
示例4: show
void show() {
// simply runs the frame
strip.show();
}
示例5: allLedsOn
void SparkButton::allLedsOn(uint8_t r, uint8_t g, uint8_t b){
for(int i = 0; i<PIXEL_COUNT; i++){
ring.setPixelColor(i, ring.Color(r, g, b));
}
ring.show();
}
示例6: loop
void loop() {
float vol_value = analogRead(VOLPIN);
char str[5];
int val;
if(isDebug == 0 && isServoDone == 0){
//for button
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
//ボタンが押されたらサーボ起動、移動後にFlahsAirの初期化 (TODO 先に初期化するとサーボが動かないバグのため暫定)
Serial.println("Btn High!!!!yeah");
//時計周りに 0 度の方向へ、そして戻した後に、FAを起動
moveServoShaft(0, 1);
moveServoShaft(90, 1);
delay(1000);
isDebug = 1;
// Initialize SD card.
Serial.print(F("\nInitializing SD card..."));
if (card.init(SPI_HALF_SPEED, chipSelectPin)) {
Serial.print(F("OK"));
} else {
Serial.print(F("NG"));
abort();
}
memset(buffer, 0, 0x200);
}else {
//nothing
}
int d = Serial.read();
if( d == 'a' ){
sv.attach(SERVO_PIN);
}
else if( d == 'd' ){
sv.detach();
}
else if( d == 'r' ){
Serial.println(sv.read());
Serial.println(sv.readMicroseconds());
}
else if( '0' <= d && d <= '9' ){
//時計周りに 0 度の方向へそして戻してFA移動
moveServoShaft(0, 10);
moveServoShaft(90, 10);
delay(1000);
//サーボ終了
isServoDone = 1;
// Initialize SD card.
Serial.print(F("\nInitializing SD card..."));
if (card.init(SPI_HALF_SPEED, chipSelectPin)) {
Serial.print(F("OK"));
} else {
Serial.print(F("NG"));
abort();
}
memset(buffer, 0, 0x200);
}
//}
}else{
if (card.readExtMemory(1, 1, 0x1000, 0x200, buffer)) {
str[0] = buffer[0];
str[1] = buffer[1];
str[2] = buffer[2];
str[3] = buffer[3];
str[4] = 0;
val = atoi(str);
//0バイトの場合初期化
if(currentByte != 0 && val == 0){
strip.clear();
strip.show();
Serial.println("back to start");
currentByte = 0;
}
if(val == 0 || val == currentByte){
//do nothing...
//Serial.println("get 1...");
}else{
if (vol_value < 800){
//Serial.println("byte changed...");
currentByte = val;
showLed3AndHelloServo(val);
Serial.println(val);
}else{
strip.clear();
strip.show();
}
}
}
}
//.........这里部分代码省略.........
示例7: ball
void ball(void)
{
static double speed = 5;
static double friction = 0.01;
static double position = 0;
double pi = 3.14159;
MPU6050::Values values;
double forceAngle = 00;
double forceNorme = 0;
uint8_t ii, count, led;
Serial.print("position ");
Serial.println(position);
mpu.readValues(&values, NULL);
Serial.print("x accel ");
Serial.print(values.xAccel);
Serial.print(" y accel ");
Serial.println(values.yAccel);
values.yAccel = -values.yAccel;
if (values.xAccel == 0) {
if (values.yAccel < 0) {
forceAngle = -90;
} else {
forceAngle = 90;
}
} else {
forceAngle = atan((double)values.yAccel / (double)values.xAccel) * 180 / pi;
if (values.xAccel < 0) {
forceAngle -= 180;
}
}
forceNorme = sqrt(values.yAccel * values.yAccel + values.xAccel * values.xAccel);
forceNorme = forceNorme / 50000.0;
Serial.print("angle ");
Serial.print(forceAngle);
Serial.print(" diff angle ");
Serial.print(position - forceAngle);
Serial.print(" force ");
Serial.println(sin((position - forceAngle) * pi / 180.0) * forceNorme);
speed -= sin((position - forceAngle) * pi / 180.0) * forceNorme;
if (speed > 0 && speed > friction) {
speed -= friction;
} else if (speed < 0 && -speed > friction) {
speed += friction;
} else {
speed = 0;
}
position += speed;
while (position > 360) {
position -= 360;
}
while (position < 0) {
position += 360;
}
count = strip1.numPixels();
led = position * count / 360.0;
for (ii = 0; ii < count; ii++) {
if (led == ii) {
strip1.setPixelColor(ii, 0x0f0f0f);
} else {
strip1.setPixelColor(ii, 0);
}
}
Serial.print("position ");
Serial.print(position);
Serial.print(" speed ");
Serial.print(speed);
Serial.print(" led ");
Serial.println(led);
strip1.show();
}
示例8: colorSet
void colorSet(uint32_t c) {
for (uint16_t i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, c);
}
strip.show();
}
示例9: go
//********************** ORDER EACH PIN to set the requested value
void go(int value1, int value2, int ctr, int ctg, int ctb, int flr, int flg, int flb, int frr, int frg, int frb, int blr, int blg, int blb, int brr, int brg, int brb){
/*
Serial.println("**************************************");
Serial.print("CENTER : ");
Serial.print(ctr);
Serial.print(",");
Serial.print(ctg);
Serial.print(",");
Serial.print(ctb);
Serial.println("");
Serial.print("FRONT LEFT : ");
Serial.print(flr);
Serial.print(",");
Serial.print(flg);
Serial.print(",");
Serial.print(flb);
Serial.println("");
Serial.print("FRONT RIGHT : ");
Serial.print(frr);
Serial.print(",");
Serial.print(frg);
Serial.print(",");
Serial.print(frb);
Serial.println("");
Serial.print("BOT LEFT : ");
Serial.print(blr);
Serial.print(",");
Serial.print(blg);
Serial.print(",");
Serial.print(blb);
Serial.println("");
Serial.print("BOT RIGHT : ");
Serial.print(brr);
Serial.print(",");
Serial.print(brg);
Serial.print(",");
Serial.println(brb);
Serial.println("---------------------------------------");
*/
if(value1<0) {
digitalWrite(M1,LOW);
analogWrite(E1, abs(value1));
}
else{
digitalWrite(M1,HIGH);
analogWrite(E1, abs(value1));
}
if(value2<0) {
digitalWrite(M2, LOW);
analogWrite(E2, abs(value2));
}
else{
digitalWrite(M2, HIGH);
analogWrite(E2, abs(value2));
}
//Invidual leds installed in the ears
//analogWrite(RL1, ctr);
//analogWrite(GL1, ctg);
//analogWrite(BL1, ctb);
//analogWrite(RL2, ctr);
//analogWrite(GL2, ctg);
//analogWrite(BL2, ctb);
//Leds in series used in the ears
ears.setPixelColor(0, pixels.Color(ctr,ctg,ctb));
ears.setPixelColor(1, pixels.Color(ctr,ctg,ctb));
ears.show();
int i;
for (i=0; i<=3; i++)
show_led_circle(i, frr,frg,frb);
for (i=4; i<=9; i++)
show_led_circle(i, brr,brg,brb);
for (i=10; i<=15; i++)
show_led_circle(i, blr,blg,blb);
for (i=16; i<=20; i++)
show_led_circle(i, flr,flg,flb);
}
示例10: BlackSpiral
void Sheet::BlackSpiral (uint8_t wait) {
uint16_t i;
for (i = 0; i < 30; i++) {
strip.setPixelColor(i, 0);
strip.setPixelColor(390 + i, 0);
strip.setPixelColor(210 - i, 0);
strip.setPixelColor(211 + i, 0);
strip.setPixelColor(59 - i, 0);
strip.setPixelColor(361 + i, 0);
strip.setPixelColor(89 - i, 0);
strip.setPixelColor(331 + i, 0);
strip.setPixelColor(119 - i, 0);
strip.setPixelColor(301 + i, 0);
strip.setPixelColor(149 - i, 0);
strip.setPixelColor(271 + i, 0);
strip.setPixelColor(180 - i, 0);
strip.setPixelColor(241 + i, 0);
strip.show();
delay(wait);
}
}
示例11: init
void Sheet::init () {
strip.begin();
strip.setBrightness(brightness); // Not really necessary, seems that the default of the library is max brightness
strip.show(); // Initialize all pixels to 'off'
}
示例12: update
void Sheet::update (bool show) {
if (show) {
strip.show();
}
}
示例13: allRainbowPulseStrobe
void Sheet::allRainbowPulseStrobe () {
int i;
for(int j = 0 ; j < 255; j++) {
for(i = 0; i < 30; i++) {
strip.setPixelColor(i, Wheel(j));
strip.setPixelColor(419 - i, Wheel(j));
}
for(i = 30; i < 60; i++) {
strip.setPixelColor(i, Wheel((j+10)));
strip.setPixelColor(419 - i, Wheel((j+10)));
}
for(i = 60; i < 90; i++) {
strip.setPixelColor(i, Wheel((j+20)));
strip.setPixelColor(419 - i, Wheel((j+20)));
}
for(i = 90; i < 120; i++) {
strip.setPixelColor(i, Wheel((j+30)));
strip.setPixelColor(419 - i, Wheel((j+30)));
}
for(i = 120; i < 150; i++) {
strip.setPixelColor(i, Wheel((j+40)));
strip.setPixelColor(419 - i, Wheel((j+40)));
}
for(i = 150; i < 180; i++) {
strip.setPixelColor(i, Wheel((j+50)));
strip.setPixelColor(419 - i, Wheel((j+50)));
}
for(i = 180; i < 210; i++) {
strip.setPixelColor(i, Wheel((j+60)));
strip.setPixelColor(419 - i, Wheel((j+60)));
}
strip.show();
SetColor(1, 0, 0, 0, false);
SetColor(2, 0, 0, 0, false);
SetColor(3, 0, 0, 0, false);
SetColor(4, 0, 0, 0, false);
SetColor(5, 0, 0, 0, false);
SetColor(6, 0, 0, 0, false);
SetColor(7, 0, 0, 0, true);
delay(20);
}
}
示例14: allRainbowPulse
void Sheet::allRainbowPulse (uint8_t wait) {
uint8_t i, j;
for(j = 0 ; j < 255; j++) {
for(i = 0; i < 30; i++) {
strip.setPixelColor(i, Wheel(j));
strip.setPixelColor(419 - i, Wheel(j));
}
for(i = 30; i < 60; i++) {
strip.setPixelColor(i, Wheel((j+10)));
strip.setPixelColor(419 - i, Wheel((j+10)));
}
for(i = 60; i < 90; i++) {
strip.setPixelColor(i, Wheel((j+20)));
strip.setPixelColor(419 - i, Wheel((j+20)));
}
for(i = 90; i < 120; i++) {
strip.setPixelColor(i, Wheel((j+30)));
strip.setPixelColor(419 - i, Wheel((j+30)));
}
for(i = 120; i < 150; i++) {
strip.setPixelColor(i, Wheel((j+40)));
strip.setPixelColor(419 - i, Wheel((j+40)));
}
for(i = 150; i < 180; i++) {
strip.setPixelColor(i, Wheel((j+50)));
strip.setPixelColor(419 - i, Wheel((j+50)));
}
for(i = 180; i < 210; i++) {
strip.setPixelColor(i, Wheel((j+60)));
strip.setPixelColor(419 - i, Wheel((j+60)));
}
strip.show();
delay(wait);
}
}
示例15: loop
void loop() {
mil = millis();
/*
if( mil > when_next ){ // debug, mrygaj co 1 sek
if( bitRead(sending, 0 ) ){ sendVal(0);}
if( bitRead(sending, 1 ) ){ sendVal(1);}
if( bitRead(sending, 2 ) ){ sendVal(2);}
if( bitRead(sending, 3 ) ){ sendVal(3);}
if( bitRead(sending, 4 ) ){ sendVal(4);}
if( bitRead(sending, 5 ) ){ sendVal(5);}
if( bitRead(sending, 6 ) ){ sendVal(6);}
if( bitRead(sending, 7 ) ){ sendVal(7);}
if( bitRead(sending, 8 ) ){ sendVal(8);}
if(sending > 0){
Serial.println();
}
when_next = mil + time;
}*/
if( pcb_type == 3 && divider-- == 0 ){
boolean power = digitalRead( PIN_B3_POWER_SENSOR );
if( power == LOW ){
low_for_sure++;
divider = PWR_SENSOR_DIV/2; // high speed checking
if( low_for_sure > 90 ){
Serial.println("F0");
Serial.flush();
}
}else{
low_for_sure = 0;
divider = PWR_SENSOR_DIV;
}
}
readHall();
step_servoY();
step_servoZ();
if(stepperIsReady){
sendStepperReady();
stepperIsReady = false;
}
/*
if(pre--){
int16_t val1 = analogRead( PIN_B2_WEIGHT );
agv = (val1 + agv * 3)>>2;
if( val1 - agv > 2 ){
byte r = abs(val1 - agv);
bottom_panels.setPixelColor(0, r,0,0 );
bottom_panels.show();
}else if( val1 - agv < 2 ){
byte g = abs(val1 - agv);
bottom_panels.setPixelColor(1, 0,g,0 );
bottom_panels.show();
}
}*/
if( mil - last_android > MAX_TIME_WITHOUT_ANDROID ){ // no android
last_android = mil;
disableServosNow();
stepperX.disableOutputs();
// unsigned long int color = bottom_panels.Color(20, 0, 0 );
// set_all_leds(color);
Serial.println("RRNOMASTER");
Serial.flush();
}
if( servo_start_time != 0 ){
unsigned long period = millis() - servo_start_time;
if( period > SERVO_MAX_TIME ){ // emergency stop
disableServosNow();
servo_start_time = 0;
unsigned long int color = bottom_panels.Color(255, 0, 0 );
set_all_leds(color);
Serial.println("RRSERVOOFF");
Serial.flush();
}
}
if( mil - last_poke > POKE_ANDROID_TIME ){ // no android
Serial.print("POKE ");
Serial.println(String(mil));
Serial.flush();
last_poke = mil;
}
}