Помогите с кодом

_A_r_d_u_i_n_o
Offline
Зарегистрирован: 02.08.2015

Здравствуйте уважаемые форумчане, делаю интересный проект, и возникли проблемы и вопросы 

вот сделал такой код 

  
#define REMOTEXY_MODE__HC05_HARDSERIAL

#include <RemoteXY.h> 

/* настройки соединения */ 
#define REMOTEXY_SERIAL Serial 
#define REMOTEXY_SERIAL_SPEED 9600 




/* конфигурация интерфейса  */ 
unsigned char RemoteXY_CONF[] = 
  { 4,0,31,0,5,5,0,4,0,2
  ,1,12,59,1,4,0,16,1,12,59
  ,4,4,0,30,1,12,59,6,3,5
  ,52,8,11,50,2 }; 
   
/* структура определяет все переменные вашего интерфейса управления */ 
struct { 

    /* input variable */
  signed char slider_1; /* =0..100 положение слайдера */
  signed char slider_2; /* =0..100 положение слайдера */
  signed char slider_3; /* =0..100 положение слайдера */
  unsigned char select_1; /* =0 если переключатель в положении A, =1 если в положении B, =2 если в положении C, ... */

    /* other variable */
  unsigned char connect_flag;  /* =1 if wire connected, else =0 */

} RemoteXY; 

///////////////////////////////////////////// 
//           END RemoteXY include          // 
///////////////////////////////////////////// 

#include "FastLED.h"

#define DATA_PIN     3
#define NUM_LEDS    45


CRGB leds[NUM_LEDS];

#define pot1 A0
#define pot2 A1
#define pot3 A2

void setup()  
{ 
  RemoteXY_Init ();  
   
   delay(2000);
 FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);


// пин с потенциометром - вход

pinMode(pot1, INPUT);
pinMode(pot2, INPUT);
pinMode(pot3, INPUT);

  RemoteXY.slider_1 = 0;
 RemoteXY.slider_2 = 0;
 RemoteXY.slider_3 = 0; // TODO you setup code 
   
} 

void loop()  
{  
  RemoteXY_Handler (); 
   
   int X;
int Y;
int Z;

  if (RemoteXY.select_1==0) { 
    /*  текущее состояние A */ 
  } 
  else if (RemoteXY.select_1==1) { 
 X=   RemoteXY.slider_1*2.55;
Y=   RemoteXY.slider_2*2.55;
Z=  RemoteXY.slider_3*2.55;  // TODO you loop code 
for (int i = 0; i < NUM_LEDS; i++) leds[i] = CRGB(X,Y,Z);
   FastLED.show(); // используйте структуру RemoteXY для передачи данных 
delay(1);    /*  текущее состояние B */ 
  } 
  else if (RemoteXY.select_1==2) { 
 X = (analogRead(pot1) / 4) ;
Y = (analogRead(pot2) / 4);
Z = (analogRead(pot3) / 4) ;
// выдаём результат на светодиод

for (int i = 0; i < NUM_LEDS; i++) leds[i] = CRGB(X,Y,Z);
   FastLED.show();   /*  текущее состояние C */ 
  } 
  else if (RemoteXY.select_1==3) { 
    /*  текущее состояние D */ 
 for (int i = 0; i < NUM_LEDS; i++) leds[i] = CRGB(0,0,255);
   FastLED.show(); // используйте структуру RemoteXY для передачи данных 
delay(1);
  } 


  
  
  
  
  
  
  
  
  
  // TODO you loop code 
  // используйте структуру RemoteXY для передачи данных 


}

и возник такой вопрос: возможно ли менять положение переключателя при помощи кнопки (т.е. RemoteXY.select_1== число - положение переключателя)

_A_r_d_u_i_n_o
Offline
Зарегистрирован: 02.08.2015

и возникла проблема, при объединении с таким вот кодом (пример из библиотеки FASTled 

#include "FastLED.h"

FASTLED_USING_NAMESPACE

// FastLED "100-lines-of-code" demo reel, showing just a few 
// of the kinds of animation patterns you can quickly and easily 
// compose using FastLED.  
//
// This example also shows one easy way to define multiple 
// animations patterns and have them automatically rotate.
//
// -Mark Kriegsman, December 2014

#if defined(FASTLED_VERSION) && (FASTLED_VERSION < 3001000)
#warning "Requires FastLED 3.1 or later; check github for latest code."
#endif

#define DATA_PIN    3
//#define CLK_PIN   4
#define LED_TYPE    WS2811
#define COLOR_ORDER GRB
#define NUM_LEDS    64
CRGB leds[NUM_LEDS];

#define BRIGHTNESS          96
#define FRAMES_PER_SECOND  120

void setup() {
  delay(3000); // 3 second delay for recovery
  
  // tell FastLED about the LED strip configuration
  FastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
  //FastLED.addLeds<LED_TYPE,DATA_PIN,CLK_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);

  // set master brightness control
  FastLED.setBrightness(BRIGHTNESS);
}


// List of patterns to cycle through.  Each is defined as a separate function below.
typedef void (*SimplePatternList[])();
SimplePatternList gPatterns = { rainbow, rainbowWithGlitter, confetti, sinelon, juggle, bpm };

uint8_t gCurrentPatternNumber = 0; // Index number of which pattern is current
uint8_t gHue = 0; // rotating "base color" used by many of the patterns
  
void loop()
{
  // Call the current pattern function once, updating the 'leds' array
  gPatterns[gCurrentPatternNumber]();

  // send the 'leds' array out to the actual LED strip
  FastLED.show();  
  // insert a delay to keep the framerate modest
  FastLED.delay(1000/FRAMES_PER_SECOND); 

  // do some periodic updates
  EVERY_N_MILLISECONDS( 20 ) { gHue++; } // slowly cycle the "base color" through the rainbow
  EVERY_N_SECONDS( 10 ) { nextPattern(); } // change patterns periodically
}

#define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))

void nextPattern()
{
  // add one to the current pattern number, and wrap around at the end
  gCurrentPatternNumber = (gCurrentPatternNumber + 1) % ARRAY_SIZE( gPatterns);
}

void rainbow() 
{
  // FastLED's built-in rainbow generator
  fill_rainbow( leds, NUM_LEDS, gHue, 7);
}

void rainbowWithGlitter() 
{
  // built-in FastLED rainbow, plus some random sparkly glitter
  rainbow();
  addGlitter(80);
}

void addGlitter( fract8 chanceOfGlitter) 
{
  if( random8() < chanceOfGlitter) {
    leds[ random16(NUM_LEDS) ] += CRGB::White;
  }
}

void confetti() 
{
  // random colored speckles that blink in and fade smoothly
  fadeToBlackBy( leds, NUM_LEDS, 10);
  int pos = random16(NUM_LEDS);
  leds[pos] += CHSV( gHue + random8(64), 200, 255);
}

void sinelon()
{
  // a colored dot sweeping back and forth, with fading trails
  fadeToBlackBy( leds, NUM_LEDS, 20);
  int pos = beatsin16(13,0,NUM_LEDS);
  leds[pos] += CHSV( gHue, 255, 192);
}

void bpm()
{
  // colored stripes pulsing at a defined Beats-Per-Minute (BPM)
  uint8_t BeatsPerMinute = 62;
  CRGBPalette16 palette = PartyColors_p;
  uint8_t beat = beatsin8( BeatsPerMinute, 64, 255);
  for( int i = 0; i < NUM_LEDS; i++) { //9948
    leds[i] = ColorFromPalette(palette, gHue+(i*2), beat-gHue+(i*10));
  }
}

void juggle() {
  // eight colored dots, weaving in and out of sync with each other
  fadeToBlackBy( leds, NUM_LEDS, 20);
  byte dothue = 0;
  for( int i = 0; i < 8; i++) {
    leds[beatsin16(i+7,0,NUM_LEDS)] |= CHSV(dothue, 200, 255);
    dothue += 32;
  }
}
 #    pragma message "FastLED version 3.001.001"
 
                     ^
 
sketch_aug01a:82: error: 'rainbow' was not declared in this scope
 
 SimplePatternList gPatterns = { rainbow, rainbowWithGlitter, confetti, sinelon, juggle, bpm };
 
                                 ^
 
sketch_aug01a:82: error: 'rainbowWithGlitter' was not declared in this scope
 
 SimplePatternList gPatterns = { rainbow, rainbowWithGlitter, confetti, sinelon, juggle, bpm };
 
                                          ^
 
sketch_aug01a:82: error: 'confetti' was not declared in this scope
 
 SimplePatternList gPatterns = { rainbow, rainbowWithGlitter, confetti, sinelon, juggle, bpm };
 
                                                              ^
 
sketch_aug01a:82: error: 'sinelon' was not declared in this scope
 
 SimplePatternList gPatterns = { rainbow, rainbowWithGlitter, confetti, sinelon, juggle, bpm };
 
                                                                        ^
 
sketch_aug01a:82: error: 'juggle' was not declared in this scope
 
 SimplePatternList gPatterns = { rainbow, rainbowWithGlitter, confetti, sinelon, juggle, bpm };
 
                                                                                 ^
 
sketch_aug01a:82: error: 'bpm' was not declared in this scope
 
 SimplePatternList gPatterns = { rainbow, rainbowWithGlitter, confetti, sinelon, juggle, bpm };
 
                                                                                         ^
 
C:\Users\Pavel\AppData\Local\Temp\arduino_0cf088fbbb461b1c1d80f673075ed229\sketch_aug01a.ino: In function 'void loop()':
 
sketch_aug01a:139: error: 'nextPattern' was not declared in this scope
 
   EVERY_N_SECONDS( 10 ) { nextPattern(); } // change patterns periodically
 
                                       ^
 
sketch_aug01a:145: error: a function-definition is not allowed here before '{' token
 
 {
 
 ^
 
sketch_aug01a:151: error: a function-definition is not allowed here before '{' token
 
 {
 
 ^
 
sketch_aug01a:157: error: a function-definition is not allowed here before '{' token
 
 {
 
 ^
 
sketch_aug01a:164: error: a function-definition is not allowed here before '{' token
 
 {
 
 ^
 
sketch_aug01a:221: error: expected '}' at end of input
 
 }
 
 ^
 
 
exit status 1
'rainbow' was not declared in this scope
 
_A_r_d_u_i_n_o
Offline
Зарегистрирован: 02.08.2015

получил вот такой код, подскажите, что я неправильно сделал при объединении 

#define REMOTEXY_MODE__HC05_HARDSERIAL

#include <RemoteXY.h> 

/* настройки соединения */ 
#define REMOTEXY_SERIAL Serial 
#define REMOTEXY_SERIAL_SPEED 9600 




/* конфигурация интерфейса  */ 
unsigned char RemoteXY_CONF[] = 
  { 4,0,31,0,5,5,0,4,0,2
  ,1,12,59,1,4,0,16,1,12,59
  ,4,4,0,30,1,12,59,6,3,5
  ,52,8,11,50,2 }; 
   
/* структура определяет все переменные вашего интерфейса управления */ 
struct { 

    /* input variable */
  signed char slider_1; /* =0..100 положение слайдера */
  signed char slider_2; /* =0..100 положение слайдера */
  signed char slider_3; /* =0..100 положение слайдера */
  unsigned char select_1; /* =0 если переключатель в положении A, =1 если в положении B, =2 если в положении C, ... */

    /* other variable */
  unsigned char connect_flag;  /* =1 if wire connected, else =0 */

} RemoteXY; 

///////////////////////////////////////////// 
//           END RemoteXY include          // 
///////////////////////////////////////////// 

#include "FastLED.h"

FASTLED_USING_NAMESPACE

#define DATA_PIN     3
#define NUM_LEDS    45
#define LED_TYPE    WS2811
#define COLOR_ORDER GRB
#define BRIGHTNESS          96
#define FRAMES_PER_SECOND  120

CRGB leds[NUM_LEDS];

#define pot1 A0
#define pot2 A1
#define pot3 A2

void setup()  
{ 
  RemoteXY_Init ();  
   
   delay(2000);
 FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
FastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
  //FastLED.addLeds<LED_TYPE,DATA_PIN,CLK_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);

  // set master brightness control
  FastLED.setBrightness(BRIGHTNESS);

// пин с потенциометром - вход

pinMode(pot1, INPUT);
pinMode(pot2, INPUT);
pinMode(pot3, INPUT);

  RemoteXY.slider_1 = 0;
 RemoteXY.slider_2 = 0;
 RemoteXY.slider_3 = 0; // TODO you setup code 




}

typedef void (*SimplePatternList[])();
SimplePatternList gPatterns = { rainbow, rainbowWithGlitter, confetti, sinelon, juggle, bpm };

uint8_t gCurrentPatternNumber = 0; // Index number of which pattern is current
uint8_t gHue = 0; // rotating "base color" used by many of the patterns
  




   
 

void loop()  
{  
  RemoteXY_Handler (); 
   
   int X;
int Y;
int Z;

  if (RemoteXY.select_1==0) { 
    /*  текущее состояние A */ 
  } 
  else if (RemoteXY.select_1==1) { 
 X=   RemoteXY.slider_1*2.55;
Y=   RemoteXY.slider_2*2.55;
Z=  RemoteXY.slider_3*2.55;  // TODO you loop code 
for (int i = 0; i < NUM_LEDS; i++) leds[i] = CRGB(X,Y,Z);
   FastLED.show(); // используйте структуру RemoteXY для передачи данных 
delay(1);    /*  текущее состояние B */ 
  } 
  else if (RemoteXY.select_1==2) { 
 X = (analogRead(pot1) / 4) ;
Y = (analogRead(pot2) / 4);
Z = (analogRead(pot3) / 4) ;
// выдаём результат на светодиод

for (int i = 0; i < NUM_LEDS; i++) leds[i] = CRGB(X,Y,Z);
   FastLED.show();   /*  текущее состояние C */ 
  } 
  else if (RemoteXY.select_1==3) { 
    /*  текущее состояние D */ 
 for (int i = 0; i < NUM_LEDS; i++) leds[i] = CRGB(0,0,255);
   FastLED.show(); // используйте структуру RemoteXY для передачи данных 
delay(1);
  } 
 else if (RemoteXY.select_1==4) { 

 gPatterns[gCurrentPatternNumber]();

  // send the 'leds' array out to the actual LED strip
  FastLED.show();  
  // insert a delay to keep the framerate modest
  FastLED.delay(1000/FRAMES_PER_SECOND); 

  // do some periodic updates
  EVERY_N_MILLISECONDS( 20 ) { gHue++; } // slowly cycle the "base color" through the rainbow
  EVERY_N_SECONDS( 10 ) { nextPattern(); } // change patterns periodically
}

#define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))

void nextPattern()
{
  // add one to the current pattern number, and wrap around at the end
  gCurrentPatternNumber = (gCurrentPatternNumber + 1) % ARRAY_SIZE( gPatterns);
}

void rainbow() 
{
  // FastLED's built-in rainbow generator
  fill_rainbow( leds, NUM_LEDS, gHue, 7);
}

void rainbowWithGlitter() 
{
  // built-in FastLED rainbow, plus some random sparkly glitter
  rainbow();
  addGlitter(80);
}

void addGlitter( fract8 chanceOfGlitter) 
{
  if( random8() < chanceOfGlitter) {
    leds[ random16(NUM_LEDS) ] += CRGB::White;
  }
}

void confetti() 
{
  // random colored speckles that blink in and fade smoothly
  fadeToBlackBy( leds, NUM_LEDS, 10);
  int pos = random16(NUM_LEDS);
  leds[pos] += CHSV( gHue + random8(64), 200, 255);
}

void sinelon()
{
  // a colored dot sweeping back and forth, with fading trails
  fadeToBlackBy( leds, NUM_LEDS, 20);
  int pos = beatsin16(13,0,NUM_LEDS);
  leds[pos] += CHSV( gHue, 255, 192);
}

void bpm()
{
  // colored stripes pulsing at a defined Beats-Per-Minute (BPM)
  uint8_t BeatsPerMinute = 62;
  CRGBPalette16 palette = PartyColors_p;
  uint8_t beat = beatsin8( BeatsPerMinute, 64, 255);
  for( int i = 0; i < NUM_LEDS; i++) { //9948
    leds[i] = ColorFromPalette(palette, gHue+(i*2), beat-gHue+(i*10));
  }
}

void juggle() {
  // eight colored dots, weaving in and out of sync with each other
  fadeToBlackBy( leds, NUM_LEDS, 20);
  byte dothue = 0;
  for( int i = 0; i < 8; i++) {
    leds[beatsin16(i+7,0,NUM_LEDS)] |= CHSV(dothue, 200, 255);
    dothue += 32;
  }

  } 

  
  
  
  
  
  
  
  
  
  // TODO you loop code 
  // используйте структуру RemoteXY для передачи данных 


}

 

T.Rook
Offline
Зарегистрирован: 05.03.2016

_A_r_d_u_i_n_o пишет:

получил вот такой код, подскажите, что я неправильно сделал при объединении 

Начнем:

1. Разберитесь с {}. LOOP должен заканчиваться на 140 строке. Что за "хвост" с 216?

Клапауций 232
Offline
Зарегистрирован: 05.04.2016

_A_r_d_u_i_n_o пишет:

получил вот такой код, подскажите, что я неправильно сделал при объединении 

я два года тому единоличным указом запретил объединять скетчи.

_A_r_d_u_i_n_o
Offline
Зарегистрирован: 02.08.2015

там нужно, чтобы при различных положения переключателя выполняли различные функции, и я вас немного не понял, просто в примере loop открывается и закрывается 

void loop()
{
  // Call the current pattern function once, updating the 'leds' array
  gPatterns[gCurrentPatternNumber]();

  // send the 'leds' array out to the actual LED strip
  FastLED.show();  
  // insert a delay to keep the framerate modest
  FastLED.delay(1000/FRAMES_PER_SECOND); 

  // do some periodic updates
  EVERY_N_MILLISECONDS( 20 ) { gHue++; } // slowly cycle the "base color" through the rainbow
  EVERY_N_SECONDS( 10 ) { nextPattern(); } // change patterns periodically
}

#define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))

void nextPattern()
{
  // add one to the current pattern number, and wrap around at the end
  gCurrentPatternNumber = (gCurrentPatternNumber + 1) % ARRAY_SIZE( gPatterns);
}

void rainbow() 
{
  // FastLED's built-in rainbow generator
  fill_rainbow( leds, NUM_LEDS, gHue, 7);
}

void rainbowWithGlitter() 
{
  // built-in FastLED rainbow, plus some random sparkly glitter
  rainbow();
  addGlitter(80);
}

void addGlitter( fract8 chanceOfGlitter) 
{
  if( random8() < chanceOfGlitter) {
    leds[ random16(NUM_LEDS) ] += CRGB::White;
  }
}

void confetti() 
{
  // random colored speckles that blink in and fade smoothly
  fadeToBlackBy( leds, NUM_LEDS, 10);
  int pos = random16(NUM_LEDS);
  leds[pos] += CHSV( gHue + random8(64), 200, 255);
}

void sinelon()
{
  // a colored dot sweeping back and forth, with fading trails
  fadeToBlackBy( leds, NUM_LEDS, 20);
  int pos = beatsin16(13,0,NUM_LEDS);
  leds[pos] += CHSV( gHue, 255, 192);
}

void bpm()
{
  // colored stripes pulsing at a defined Beats-Per-Minute (BPM)
  uint8_t BeatsPerMinute = 62;
  CRGBPalette16 palette = PartyColors_p;
  uint8_t beat = beatsin8( BeatsPerMinute, 64, 255);
  for( int i = 0; i < NUM_LEDS; i++) { //9948
    leds[i] = ColorFromPalette(palette, gHue+(i*2), beat-gHue+(i*10));
  }
}

void juggle() {
  // eight colored dots, weaving in and out of sync with each other
  fadeToBlackBy( leds, NUM_LEDS, 20);
  byte dothue = 0;
  for( int i = 0; i < 8; i++) {
    leds[beatsin16(i+7,0,NUM_LEDS)] |= CHSV(dothue, 200, 255);
    dothue += 32;
  }
}

а затем идут другие void и вот мне нужно чтобы при определённом положении переключателя работали вот эти juggle bmp и другие, я пробовал менять скобки и так и не понял, как сделать, чтобы работал код

_A_r_d_u_i_n_o
Offline
Зарегистрирован: 02.08.2015

Клапауций 232 пишет:

_A_r_d_u_i_n_o пишет:

получил вот такой код, подскажите, что я неправильно сделал при объединении 

я два года тому единоличным указом запретил объединять скетчи.

а как их тогда объединить?

Клапауций 232
Offline
Зарегистрирован: 05.04.2016

_A_r_d_u_i_n_o пишет:

а как их тогда объединить?

переспросишь после своей казни за нарушение моего указа.

_A_r_d_u_i_n_o
Offline
Зарегистрирован: 02.08.2015

Клапауций 232 пишет:

_A_r_d_u_i_n_o пишет:

а как их тогда объединить?

переспросишь после своей казни за нарушение моего указа.

тогда как добавить эти же функции в первоначальный код? 

Cessi71
Offline
Зарегистрирован: 21.05.2016

Вам же написали- лишняя фигурная скобка.

_A_r_d_u_i_n_o
Offline
Зарегистрирован: 02.08.2015

большое спасибо, а теперь второй вопрос возможно ли менять положение переключателя (допустим с пятью положениями) при помощи внешней кнопки, подключённой к аналоговому пину? ( переключатель имеется ввиду такойhttp://remotexy.com/ru/help/controls/select/)

T.Rook
Offline
Зарегистрирован: 05.03.2016

удалено