помогите со скобками
- Войдите на сайт для отправки комментариев
Пт, 04/11/2016 - 13:38
Здравствуйте, возникла проблема с объединением кодов, вот пытался объединить вот эти два кода, чтобы вторым режимом (т.е. в else рааботал второй код), т.е. происходило переливание цветов, а в первом режиме управление было при помощи потенциометров, вот эти коды
#define pot1 A0
#define pot2 A1
#define pot3 A2
#include "FastLED.h"
#define DATA_PIN 3
#define NUM_LEDS 45
CRGB leds[NUM_LEDS];
void setup() {
// put your setup code here, to run once:
FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
pinMode(pot1, INPUT);
pinMode(pot2, INPUT);
pinMode(pot3, INPUT);
pinMode(10, INPUT);
}
void loop() {
int X;
int Y;
int Z;
if (digitalRead(10) == LOW) { 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 {
}
// put your main code here, to run repeatedly:
}
и вот этот
#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;
}
}что-то не могу понять, как эти void вставить, постоянно ругается компилятор на скобки, прошу помочь мне, зарание благодарю
#define pot1 A0 #define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0])) #define pot2 A1 #define pot3 A2 #include "FastLED.h" #define DATA_PIN 3 #define NUM_LEDS 45 FASTLED_USING_NAMESPACE CRGB leds[NUM_LEDS]; #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) // put your setup code here, to run once: FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS); pinMode(pot1, INPUT); pinMode(pot2, INPUT); pinMode(pot3, INPUT); pinMode(10, INPUT); FastLED.setBrightness(BRIGHTNESS); } 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 "bas void loop() { int X; int Y; int Z; if (digitalRead(10) == LOW) { 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 { // 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 } // put your main code here, to run repeatedly: 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; } } }вот вроди норм
ругется...
я немного подкорректировал начало
#define pot1 A0 #define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0])) #define pot2 A1 #define pot3 A2 #include "FastLED.h" #define DATA_PIN 3 #define NUM_LEDS 45 FASTLED_USING_NAMESPACE CRGB leds[NUM_LEDS]; #if defined(FASTLED_VERSION) && (FASTLED_VERSION < 3001000) #warning "Requires FastLED 3.1 or later; check github for latest code." #endif //#define CLK_PIN 4 #define LED_TYPE WS2811 #define COLOR_ORDER GRB #define BRIGHTNESS 96 #define FRAMES_PER_SECOND 120 void setup() { delay(3000) // put your setup code here, to run once: FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS); pinMode(pot1, INPUT); pinMode(pot2, INPUT); pinMode(pot3, INPUT); pinMode(10, INPUT); FastLED.setBrightness(BRIGHTNESS); } 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 "bas void loop() { int X; int Y; int Z; if (digitalRead(10) == LOW) { 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 { // 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 } // put your main code here, to run repeatedly: 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; } } } }выдаёт такую ошибку
WARNING: Spurious .github folder in 'Adafruit NeoPixel' library In file included from C:\Users\Pavel\AppData\Local\Temp\arduino_e6e7d42a17ee034645ab75e64d1f991d\sketch_nov04a.ino:5:0: C:\Users\Pavel\Documents\Arduino\libraries\FastLED-master/FastLED.h:17:21: note: #pragma message: FastLED version 3.001.001 # pragma message "FastLED version 3.001.001" ^ C:\Users\Pavel\AppData\Local\Temp\arduino_e6e7d42a17ee034645ab75e64d1f991d\sketch_nov04a.ino: In function 'void setup()': sketch_nov04a:23: error: expected ';' before 'FastLED' FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS); ^ C:\Users\Pavel\AppData\Local\Temp\arduino_e6e7d42a17ee034645ab75e64d1f991d\sketch_nov04a.ino: At global scope: sketch_nov04a:31: error: 'rainbow' was not declared in this scope SimplePatternList gPatterns = { rainbow, rainbowWithGlitter, confetti, sinelon, juggle, bpm }; ^ sketch_nov04a:31: error: 'rainbowWithGlitter' was not declared in this scope SimplePatternList gPatterns = { rainbow, rainbowWithGlitter, confetti, sinelon, juggle, bpm }; ^ sketch_nov04a:31: error: 'confetti' was not declared in this scope SimplePatternList gPatterns = { rainbow, rainbowWithGlitter, confetti, sinelon, juggle, bpm }; ^ sketch_nov04a:31: error: 'sinelon' was not declared in this scope SimplePatternList gPatterns = { rainbow, rainbowWithGlitter, confetti, sinelon, juggle, bpm }; ^ sketch_nov04a:31: error: 'juggle' was not declared in this scope SimplePatternList gPatterns = { rainbow, rainbowWithGlitter, confetti, sinelon, juggle, bpm }; ^ sketch_nov04a:31: error: 'bpm' was not declared in this scope SimplePatternList gPatterns = { rainbow, rainbowWithGlitter, confetti, sinelon, juggle, bpm }; ^ C:\Users\Pavel\AppData\Local\Temp\arduino_e6e7d42a17ee034645ab75e64d1f991d\sketch_nov04a.ino: In function 'void loop()': sketch_nov04a:60: error: 'nextPattern' was not declared in this scope EVERY_N_SECONDS( 10 ) { nextPattern(); } // change patterns periodically ^ sketch_nov04a:64: error: a function-definition is not allowed here before '{' token { ^ sketch_nov04a:69: error: a function-definition is not allowed here before '{' token { ^ sketch_nov04a:74: error: a function-definition is not allowed here before '{' token { ^ sketch_nov04a:80: error: a function-definition is not allowed here before '{' token { ^ sketch_nov04a:118: error: expected '}' at end of input } ^ exit status 1 expected ';' before 'FastLED'подскажите, как исправить
что-то ругается...
спасибо за помощь
идей ни у кого нет?
помогите пожалуйста
#define pot1 A0 #define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0])) #define pot2 A1 #define pot3 A2 #include "FastLED.h" #define DATA_PIN 3 #define NUM_LEDS 45 FASTLED_USING_NAMESPACE CRGB leds[NUM_LEDS]; #if defined(FASTLED_VERSION) && (FASTLED_VERSION < 3001000) #warning "Requires FastLED 3.1 or later; check github for latest code." #endif //#define CLK_PIN 4 #define LED_TYPE WS2811 #define COLOR_ORDER GRB #define BRIGHTNESS 96 #define FRAMES_PER_SECOND 120 void setup() { delay(3000) // put your setup code here, to run once: FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS); pinMode(pot1, INPUT); pinMode(pot2, INPUT); pinMode(pot3, INPUT); pinMode(10, INPUT); FastLED.setBrightness(BRIGHTNESS); } 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 "bas void loop() { int X; int Y; int Z; if (digitalRead(10) == LOW) { 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 { // 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 } } } // put your main code here, to run repeatedly: 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; } } } }внимательней надо быть. если бы нормально оформлял код, такого бы не было.
Отформатируй текст (Ctrl-T) и посмотри скобки как расположены.
Если написано в ардуино ide - там даже кнопка есть форматировать... в других ide тоже
Если написано в ардуино ide - там даже кнопка есть форматировать... в других ide тоже
спасибо за помошь, но, к сожалению, продолжает ругаться
код подправил, получил вот такой
#define pot1 A0 #define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0])) #define pot2 A1 #define pot3 A2 #include "FastLED.h" #define DATA_PIN 3 #define NUM_LEDS 45 FASTLED_USING_NAMESPACE CRGB leds[NUM_LEDS]; #if defined(FASTLED_VERSION) && (FASTLED_VERSION < 3001000) #warning "Requires FastLED 3.1 or later; check github for latest code." #endif //#define CLK_PIN 4 #define LED_TYPE WS2811 #define COLOR_ORDER GRB #define BRIGHTNESS 96 #define FRAMES_PER_SECOND 120 void setup() { delay(3000); // put your setup code here, to run once: FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS); pinMode(pot1, INPUT); pinMode(pot2, INPUT); pinMode(pot3, INPUT); pinMode(10, INPUT); FastLED.setBrightness(BRIGHTNESS); } 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 "bas void loop() { int X; int Y; int Z; if (digitalRead(10) == LOW) { 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 { // 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 } // put your main code here, to run repeatedly: 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; } } } } }скобки везде сходятся, но он продолжает ругаться:
WARNING: Spurious .github folder in 'Adafruit NeoPixel' library In file included from C:\Users\Pavel\AppData\Local\Temp\arduino_e6e7d42a17ee034645ab75e64d1f991d\sketch_nov04a.ino:5:0: C:\Users\Pavel\Documents\Arduino\libraries\FastLED-master/FastLED.h:17:21: note: #pragma message: FastLED version 3.001.001 # pragma message "FastLED version 3.001.001" ^ sketch_nov04a:31: error: 'rainbow' was not declared in this scope SimplePatternList gPatterns = { rainbow, rainbowWithGlitter, confetti, sinelon, juggle, bpm }; ^ sketch_nov04a:31: error: 'rainbowWithGlitter' was not declared in this scope SimplePatternList gPatterns = { rainbow, rainbowWithGlitter, confetti, sinelon, juggle, bpm }; ^ sketch_nov04a:31: error: 'confetti' was not declared in this scope SimplePatternList gPatterns = { rainbow, rainbowWithGlitter, confetti, sinelon, juggle, bpm }; ^ sketch_nov04a:31: error: 'sinelon' was not declared in this scope SimplePatternList gPatterns = { rainbow, rainbowWithGlitter, confetti, sinelon, juggle, bpm }; ^ sketch_nov04a:31: error: 'juggle' was not declared in this scope SimplePatternList gPatterns = { rainbow, rainbowWithGlitter, confetti, sinelon, juggle, bpm }; ^ sketch_nov04a:31: error: 'bpm' was not declared in this scope SimplePatternList gPatterns = { rainbow, rainbowWithGlitter, confetti, sinelon, juggle, bpm }; ^ C:\Users\Pavel\AppData\Local\Temp\arduino_e6e7d42a17ee034645ab75e64d1f991d\sketch_nov04a.ino: In function 'void loop()': sketch_nov04a:64: error: 'nextPattern' was not declared in this scope nextPattern(); // change patterns periodically ^ sketch_nov04a:69: error: a function-definition is not allowed here before '{' token { ^ sketch_nov04a:74: error: a function-definition is not allowed here before '{' token { ^ sketch_nov04a:79: error: a function-definition is not allowed here before '{' token { ^ sketch_nov04a:85: error: a function-definition is not allowed here before '{' token { ^ sketch_nov04a:124: error: expected '}' at end of input } ^ sketch_nov04a:124: error: expected '}' at end of input exit status 1 'rainbow' was not declared in this scopeя уже не знаю, что делать...
Ну со скобками то в порядке?
Дальше надо библиотеки качать (у меня и так много хлама). К тому же где ты ее скачивал - я незнаю, и не факт что скачаю ту же самую.
Так что тут я не помогу ничем. Нормально код отформатируй, раздели на части и обратно вставь (по частям, сперва на голый скетч повесь библиотеки, потом сетап заполни...) - и увидишь где косяк.
вот такой код, всё равно на скобки ругается
#define pot1 A0 #define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0])) #define pot2 A1 #define pot3 A2 #include "FastLED.h" #define DATA_PIN 3 #define NUM_LEDS 45 FASTLED_USING_NAMESPACE CRGB leds[NUM_LEDS]; #if defined(FASTLED_VERSION) && (FASTLED_VERSION < 3001000) #warning "Requires FastLED 3.1 or later; check github for latest code." #endif //#define CLK_PIN 4 #define LED_TYPE WS2811 #define COLOR_ORDER GRB #define BRIGHTNESS 96 #define FRAMES_PER_SECOND 120 void setup() { delay(3000); // put your setup code here, to run once: FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS); pinMode(pot1, INPUT); pinMode(pot2, INPUT); pinMode(pot3, INPUT); pinMode(10, INPUT); FastLED.setBrightness(BRIGHTNESS); } 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 "bas void loop() { int X; int Y; int Z; if (digitalRead(10) == LOW) { 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 { // 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])) // put your main code here, to run repeatedly: 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; } } } } }хотя вроде подходят...
ругается так
WARNING: Spurious .github folder in 'Adafruit NeoPixel' library In file included from C:\Users\Pavel\AppData\Local\Temp\arduino_cc20c4348b77ca47a395488f2c4bddb3\sketch_nov04a.ino:5:0: C:\Users\Pavel\Documents\Arduino\libraries\FastLED-master/FastLED.h:17:21: note: #pragma message: FastLED version 3.001.005 # pragma message "FastLED version 3.001.005" ^ sketch_nov04a:31: error: 'rainbow' was not declared in this scope SimplePatternList gPatterns = { rainbow, rainbowWithGlitter, confetti, sinelon, juggle, bpm }; ^ sketch_nov04a:31: error: 'rainbowWithGlitter' was not declared in this scope SimplePatternList gPatterns = { rainbow, rainbowWithGlitter, confetti, sinelon, juggle, bpm }; ^ sketch_nov04a:31: error: 'confetti' was not declared in this scope SimplePatternList gPatterns = { rainbow, rainbowWithGlitter, confetti, sinelon, juggle, bpm }; ^ sketch_nov04a:31: error: 'sinelon' was not declared in this scope SimplePatternList gPatterns = { rainbow, rainbowWithGlitter, confetti, sinelon, juggle, bpm }; ^ sketch_nov04a:31: error: 'juggle' was not declared in this scope SimplePatternList gPatterns = { rainbow, rainbowWithGlitter, confetti, sinelon, juggle, bpm }; ^ sketch_nov04a:31: error: 'bpm' was not declared in this scope SimplePatternList gPatterns = { rainbow, rainbowWithGlitter, confetti, sinelon, juggle, bpm }; ^ C:\Users\Pavel\AppData\Local\Temp\arduino_cc20c4348b77ca47a395488f2c4bddb3\sketch_nov04a.ino: In function 'void loop()': sketch_nov04a:64: error: 'nextPattern' was not declared in this scope nextPattern(); // change patterns periodically ^ sketch_nov04a:71: error: a function-definition is not allowed here before '{' token { ^ sketch_nov04a:76: error: a function-definition is not allowed here before '{' token { ^ sketch_nov04a:81: error: a function-definition is not allowed here before '{' token { ^ sketch_nov04a:87: error: a function-definition is not allowed here before '{' token { ^ sketch_nov04a:126: error: expected '}' at end of input } ^ sketch_nov04a:126: error: expected '}' at end of input exit status 1 'rainbow' was not declared in this scopeя не понимаю......... что не так
я не понимаю......... что не так
Я писал уже. Возьми пустой скетч и проверь компилируя после каждой добавленой части (начало ругани библиотек Adafruit///)
Вот так компилится
#define pot1 A0 #define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0])) #define pot2 A1 #define pot3 A2 #include "FastLED.h" #define DATA_PIN 3 #define NUM_LEDS 45 FASTLED_USING_NAMESPACE CRGB leds[NUM_LEDS]; #if defined(FASTLED_VERSION) && (FASTLED_VERSION < 3001000) #warning "Requires FastLED 3.1 or later; check github for latest code." #endif //#define CLK_PIN 4 #define LED_TYPE WS2811 #define COLOR_ORDER GRB #define BRIGHTNESS 96 #define FRAMES_PER_SECOND 120 void setup() { delay(3000); // put your setup code here, to run once: FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS); pinMode(pot1, INPUT); pinMode(pot2, INPUT); pinMode(pot3, INPUT); pinMode(10, INPUT); FastLED.setBrightness(BRIGHTNESS); } typedef void (*SimplePatternList[])(); void rainbow(); void rainbowWithGlitter(); void confetti(); void sinelon(); void juggle(); void bpm(); void nextPattern(); void addGlitter( fract8 chanceOfGlitter); SimplePatternList gPatterns = { rainbow, rainbowWithGlitter, confetti, sinelon, juggle, bpm }; uint8_t gCurrentPatternNumber = 0; // Index number of which pattern is current uint8_t gHue = 0; // rotating "bas void addGlitter(fract8 chanceOfGlitter) { if ( random8() < chanceOfGlitter) { leds[ random16(NUM_LEDS) ] += CRGB::White; } } 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 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 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 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; } } #define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0])) // put your main code here, to run repeatedly: 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 loop() { int X; int Y; int Z; if (digitalRead(10) == LOW) { 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 { // 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 pot1 A0 #define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0])) #define pot2 A1 #define pot3 A2 #include "FastLED.h" #define DATA_PIN 3 #define NUM_LEDS 45 FASTLED_USING_NAMESPACE CRGB leds[NUM_LEDS]; #if defined(FASTLED_VERSION) && (FASTLED_VERSION < 3001000) #warning "Requires FastLED 3.1 or later; check github for latest code." #endif //#define CLK_PIN 4 #define LED_TYPE WS2811 #define COLOR_ORDER GRB #define BRIGHTNESS 96 #define FRAMES_PER_SECOND 120 void setup() { delay(3000); // put your setup code here, to run once: FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS); pinMode(pot1, INPUT); pinMode(pot2, INPUT); pinMode(pot3, INPUT); pinMode(10, INPUT); FastLED.setBrightness(BRIGHTNESS); } typedef void (*SimplePatternList[])(); void rainbow(); void rainbowWithGlitter(); void confetti(); void sinelon(); void juggle(); void bpm(); void nextPattern(); void addGlitter( fract8 chanceOfGlitter); SimplePatternList gPatterns = { rainbow, rainbowWithGlitter, confetti, sinelon, juggle, bpm }; uint8_t gCurrentPatternNumber = 0; // Index number of which pattern is current uint8_t gHue = 0; // rotating "bas void addGlitter(fract8 chanceOfGlitter) { if ( random8() < chanceOfGlitter) { leds[ random16(NUM_LEDS) ] += CRGB::White; } } 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 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 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 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; } } #define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0])) // put your main code here, to run repeatedly: 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 loop() { int X; int Y; int Z; if (digitalRead(10) == LOW) { 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 { // 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 } } }Кстати, это новая фича в ардуино - уподобаться С++ ?
Тоесть все переменные только в шапку, и функция должна находиться до вызова по коду.
Нет. Здесь в начале объявляется массив функций. До объявления массива должны быть объявлены все переменные, т.е. функции. К С++ это не имеет никакого отношения. То что ардуино это делает за вас только расслабляет. Надо сразу писать правильно. Вдруг ещё на какую-нибудь среду перейдёте. Там поблажек не будет.
Нет. Здесь в начале объявляется массив функций. До объявления массива должны быть объявлены все переменные, т.е. функции. К С++ это не имеет никакого отношения. То что ардуино это делает за вас только расслабляет. Надо сразу писать правильно. Вдруг ещё на какую-нибудь среду перейдёте. Там поблажек не будет.
Писать надо правильно - поддерживаю, но иногда влепишь функцию ниже по коду...
А последняя версия ардуины ругается что функция не обьявлена, сходу даже не понял..
Я в С не до конца еще разобрался... так основы.. Но даже в них увидел про обьявления функций и тут на ардуино заругалась.
Ничего как дочитаю, вкурю, на какой нибудь CODEVISION перейду. А там и с АРМ постепенно разберусь.