-->

从一个结构数组ARDUINO获得的值(Getting a value from a Struct A

2019-10-30 12:37发布

我有检索存储在一个结构的价值观的问题,不知道为什么。

我工作的Arduino IDE 1.8.7

.h文件

// structure to hold each "display unit" settings
typedef struct {
  int displayState;
  int pixelState[];
  int startLed; // the first LED number EG: 8 if the previous display used 0-7
  int endLed; 
  int brightness;
  int saturation;

} struct_displayType;`

在设置

// display[0] is all leds
displayUnit[0].displayState=5;
displayUnit[0].brightness=255;
displayUnit[0].startLed=0;
displayUnit[0].endLed=NUM_LEDS;
displayUnit[0].saturation=127;

displayUnit[1].displayState=5;
displayUnit[1].brightness=255;
displayUnit[1].startLed=8;
displayUnit[1].endLed=15;
displayUnit[1].saturation=127;

在循环

BreezeMapPixels(displayUnit[0],SOFT_BREEZE); 

在功能

void BreezeMapPixels(struct_displayType &mDisplayUnit, int breezeStrength)
{
  Serial.println("Breeze Module");
  Serial.println( mDisplayUnit.startLed +  mDisplayUnit.endLed);
}

Serial.println没有给存储在结构中的值。 请帮我找出问题。

*****************全码********************

void setup() { 

  pinMode(LED_PIN, OUTPUT);
  pinMode(BUTTON, INPUT);
   FastLED.addLeds<CHIPSET, LED_PIN>(leds, NUM_LEDS);
 attachInterrupt(BUTTON,interruptRoutine,RISING);

    // serial debuging
     Serial.begin(9600);      // open the serial port at 9600 bps:

  InitPixelStates(displayUnit[0]);
    // Drying Grass
LEDcolor[0]=CHSV(22,187,217); //0xAAD93A;
LEDcolor[1]=CHSV(21,184,244); //0xC2F444;
LEDcolor[2]=CHSV(21,94,180);//0xDBF49A;
LEDcolor[3]=CHSV(16,94,200);//0xF4EE9A;
LEDcolor[4]=CHSV(12,94,220); //0xF4D99A;
//
//LEDcolor[2]=CHSV(21,94,244);//0xDBF49A;
//LEDcolor[3]=CHSV(16,94,244);//0xF4EE9A;
//LEDcolor[4]=CHSV(12,94,244); //0xF4D99A;


// Define each display's LED range

// display[0] is all leds
displayUnit[0].displayState=5;
displayUnit[0].brightness=255;
displayUnit[0].startLed=0;
displayUnit[0].endLed=NUM_LEDS;
displayUnit[0].saturation=127;

displayUnit[1].displayState=5;
displayUnit[1].brightness=255;
displayUnit[1].startLed=8;
displayUnit[1].endLed=15;
displayUnit[1].saturation=127;
  Serial.println("Setup Done");

  interruptMode=1;
}

#include "definitions.h"



void loop() {

 if(interruptMode==1){ //Soft Breeze
    //      Serial.println("Rest int");
//   restingColour(displayUnit[0]);
//   restingColour(displayUnit[1]);
BreezeMapPixels(displayUnit[0],SOFT_BREEZE); 
}
 if(interruptMode==2){ // Strong Breeze
           Serial.println("Breeze int");
//     restingBreeze(displayUnit[0]);
     Serial.println("Breeze int");
BreezeMapPixels(displayUnit[0],STRONG_BREEZE); 
}
//if(interruptMode==3){ // Fluro Flicker
//  fadeToBlack();
//
//}

    FastLED.show();  
    FastLED.delay(20);
}


/* **********************************
    Start of Code
 * *********************************/
enum { SteadyDim, GettingBrighter, GettingDimmerAgain };


void InitPixelStates(struct_displayType &mDisplayUnit)
{
  for ( uint16_t i = mDisplayUnit.startLed; i < mDisplayUnit.endLed; i++) {
  mDisplayUnit.pixelState[i] == SteadyDim;
  leds[i]=BASE_COLOR;
  Serial.println(i);
  }
//  memset( PixelState, sizeof(PixelState), SteadyDim); // initialize all the pixels to SteadyDim.
 // fill_solid( leds, NUM_LEDS, CRGB(0,0,0));
}

void BreezeMapPixels(struct_displayType &mDisplayUnit, int breezeStrength)
{
 // Serial.println("Breeze Module");
    Serial.println( &mDisplayUnit.startLed + mDisplayUnit.endLed);
 // for ( uint16_t i = 0; i < NUM_LEDS; i++) {
 for ( uint16_t i = mDisplayUnit.startLed; i < mDisplayUnit.endLed; i++) {
//Serial.println("Steady " + i);
    if ( mDisplayUnit.pixelState[i] == SteadyDim) {
      // this pixels is currently: SteadyDim
      // so we randomly consider making it start getting brighter
     leds[i]=BASE_COLOR;
      if ( random8() < breezeStrength) {
        mDisplayUnit.pixelState[i] = GettingBrighter;
      }

    } else if ( mDisplayUnit.pixelState[i] == GettingBrighter ) {
         Serial.println("Brighter " + i);
      // this pixels is currently: GettingBrighter
      // so if it's at peak color, switch it to getting dimmer again
      if ( leds[i] >= PEAK_COLOR ) {

        mDisplayUnit.pixelState[i] = GettingDimmerAgain;
      } else {
        // otherwise, just keep brightening it:
        leds[i] += DELTA_COLOR_UP;
      }

    } else { // getting dimmer again
         Serial.println("Dimmer " + i);
      // this pixels is currently: GettingDimmerAgain
      // so if it's back to base color, switch it to steady dim
      if ( leds[i] <= BASE_COLOR ) {

        leds[i] = BASE_COLOR; // reset to exact base color, in case we overshot
        mDisplayUnit.pixelState[i] = SteadyDim;
      } else {
        // otherwise, just keep dimming it down:
        leds[i] -= DELTA_COLOR_DOWN;

      }
    }
  }
}

definitions.h

#include <FastLED.h>

#define NUM_LEDS 16
#define LED_PIN     6
#define CHIPSET     NEOPIXEL//WS2812B//WS2811
#define BRIGHTNESS  50
#define FRAMES_PER_SECOND 60


#define BUTTON  2 //trigger button
int interruptMode; // current mode - Testing only



// structure to hold each "display unit" settings
typedef struct {
  int displayState;
  int pixelState[];
  int startLed; // the first LED number EG: 8 if the previous display used 0-7
  int endLed; 
  int brightness;
  int saturation;

} struct_displayType;



// An array of the displays
struct_displayType displayUnit[30];

/* -------------
 * State types
 * -------------
 * 1 - resting
 * 2 - flickering
 * 3 - Warming up
 * 4 - Green
 * 5 - black
 */

/* **********************************
    Parameters for Breeze
 * *********************************/
// Parameters include: background color, peak color, and speed
// of brightening and dimming.
//

// Base green color
#define BASE_COLOR      CRGB(71, 94, 18)
// Peak green color to brighten up to
#define PEAK_COLOR      CRGB(201, 231, 131)


// Currently set to brighten up a bit faster than it dims down,
// but this can be adjusted.

// Amount to increment the color by each loop as it gets brighter:
#define DELTA_COLOR_UP   CRGB(6,6,6)

// Amount to decrement the color by each loop as it gets dimmer:
#define DELTA_COLOR_DOWN CRGB(3,3,3)


// Chance of each pixel starting to brighten up.
// 1 or 2 = a few brightening pixels at a time.
// 10 = lots of pixels brightening at a time.
#define SOFT_BREEZE 1
#define STRONG_BREEZE 5




CHSV LEDcolor[16];
文章来源: Getting a value from a Struct Array ARDUINO