Simple Neopixel code help

Hi all,

I had a strip of Neopixel laying around and thought it might be nice to do something with them. The strip is 65 pixels long so I thought I might have a go at making a neopixel clock with one colour for seconds, one for minutes and one for hours. Maybe even laser cut a simple case to present it in.

The problem is with the code. Well actually the problem is probably me !! LOL. :wink:
The code I have written is giving compile errors. I have tried a couple of things like changing case and swapping round the includes but I still can not get it to compile. The code is as follows,

'#include "neopixel/neopixel.h"
'#include "application.h"

    


void setup() {
// IMPORTANT: Set Pin, number of types and NeoPixel model
'#define NEOPIXEL_PIN D2
'#define NEOPIXEL_COUNT 60
'#define NEOPIXEL_TYPE WS2812B

Adafruit_NeoPixel strip = Adafruit_NeoPixel(NEOPIXEL_COUNT, NEOPIXEL_PIN, NEOPIXEL_TYPE);
Spark.syncTime();
Time.zone(+1);
//Time.setTime(1410302158);
strip.setBrightness(30);
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
Serial.begin(9600);
}



void loop() {
 int hour = Time.hourFormat12();
 int min = Time.minute();
 int sec = Time.second();
 // seconds
Serial.print(sec);
strip.setPixelColor(sec,50,50,50);
    strip.show();


This gives the error,

In file included from ../inc/spark_wiring.h:29:0,
from ../inc/application.h:29,
from neopixel/neopixel.h:42,
from neopixel/neopixel.cpp:39:
../../core-common-lib/SPARK_Firmware_Driver/inc/config.h:12:2: warning: #warning "Defaulting to Release Build" [-Wcpp]
'#warning "Defaulting to Release Build"
^
In file included from ../inc/spark_wiring.h:29:0,
from ../inc/application.h:29,
from neopixel/neopixel.h:42,
from neopixel_clock.cpp:6:
../../core-common-lib/SPARK_Firmware_Driver/inc/config.h:12:2: warning: #warning "Defaulting to Release Build" [-Wcpp]
'#warning "Defaulting to Release Build"
^
neopixel_clock.cpp: In function 'void setpixeltime()':
neopixel_clock.cpp:9:5: error: 'strip' was not declared in this scope

^
neopixel_clock.cpp:9:25: error: 'sec' was not declared in this scope

I get the warnings, they are fine, the code is not finished yet so there are still unused variables. It is the strip, not declared etc. It is as if the library is not added or I am not calling the function correctly. I took the function from some working code so I don’t think that is it. I have also removed and the replaced the neopixel library to see if that makes a difference.

It doesn’t.

Any help greatly appreciated.

Julian

@Julian, First, it would be helpful for readability, if you could use the code style in the editor when you paste code. So what you posted would look like:

  '#include "neopixel/neopixel.h"
  '#include "application.h"

  void setup() {
  // IMPORTANT: Set Pin, number of types and NeoPixel model
  '#define NEOPIXEL_PIN D2
  '#define NEOPIXEL_COUNT 60
  '#define NEOPIXEL_TYPE WS2812B

  Adafruit_NeoPixel strip = Adafruit_NeoPixel(NEOPIXEL_COUNT, NEOPIXEL_PIN, NEOPIXEL_TYPE);
  Spark.syncTime();
  Time.zone(+1);
  //Time.setTime(1410302158);
  strip.setBrightness(30);
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
  Serial.begin(9600);
  }

  void loop() {
  int hour = Time.hourFormat12();
  int min = Time.minute();
  int sec = Time.second();
  // seconds
  Serial.print(sec);
  strip.setPixelColor(sec,50,50,50);
  strip.show();

  This gives the error,

  In file included from ../inc/spark_wiring.h:29:0,
  from ../inc/application.h:29,
  from neopixel/neopixel.h:42,
  from neopixel/neopixel.cpp:39:
  ../../core-common-lib/SPARK_Firmware_Driver/inc/config.h:12:2: warning: #warning "Defaulting to Release Build" [-Wcpp]
  '#warning "Defaulting to Release Build"
  ^
  In file included from ../inc/spark_wiring.h:29:0,
  from ../inc/application.h:29,
  from neopixel/neopixel.h:42,
  from neopixel_clock.cpp:6:
  ../../core-common-lib/SPARK_Firmware_Driver/inc/config.h:12:2: warning: #warning "Defaulting to Release Build" [-Wcpp]
  '#warning "Defaulting to Release Build"
  ^
  neopixel_clock.cpp: In function 'void setpixeltime()':
  neopixel_clock.cpp:9:5: error: 'strip' was not declared in this scope

  ^
  neopixel_clock.cpp:9:25: error: 'sec' was not declared in this scope

From the errors, it seems like you have a function setpixeltime(), but I don’t see it anywhere in your example.

Can you post that too?

1 Like

@delianides, nice cleanup but I believe the issue lies in the single quotes on the #include and #define lines which is most likely preventing them from compiling! @Julian, remove those single quotes and try again :smile:

@peekay123 I was wondering that, but assumed that was because of the formatting. Also, the errors didn’t seem reflect that. I felt that the compiler wouldn’t have liked the NeoPixel declaration if that had been the case.

1 Like

@delianides, you may be right but without a “clean” posting of the ENTIRE code, it’s hard to be sure. @Julian, can you make a github gist of your entire code and post the link?

@delianides and @peekay123, thank you very much for your help.

To take your comments in turn

Please could you explain how I would do this? Is there a "standard" way to present code in the forum? If so, how?

@delianides, you are correct the ' is in there so that when I paste the code into the forum you don't get a
#huge text jump
In a similar way to Microsoft Excel if you put ' before your text then it appears un-formatted.

@peekay123, as you know I am a relative beginner (as my posts no doubt convey). I don't know how to make a github gist but I will work it out and post it back here.

Thank you very much for helping me understand/sort this out. :smile:

Looking into GITHUB I was wondering where the name came from as a GIT in my part of the world (maybe yours also) is, to quote wikipedia,"Git is mild pejorative with origins in British English for a silly, incompetent, stupid, annoying, senile elderly or childish person. It is usually an insult, more severe than twit or idiot."

I thought the GIT in GITHUB would be an acronym but then it turns out that the GIT in GITHUB is actually as I first thought, this from the GIT hub help page explains,

,Quoting Linus: "I'm an egotistical bastard, and I name all my projects after myself. First 'Linux', now 'Git'".
('git' is British slang for "pig headed, think they are always correct, argumentative").
Alternatively, in Linus' own words as the inventor of Git: "git" can mean anything, depending on your mood:
Random three-letter combination that is pronounceable, and not actually used by any common UNIX command. The fact that it is a mispronunciation of "get" may or may not be relevant.
Stupid. Contemptible and despicable. Simple. Take your pick from the dictionary of slang.
"Global information tracker": you're in a good mood, and it actually works for you. Angels sing and light suddenly fills the room.
"Goddamn idiotic truckload of sh*t": when it breaks

Thanks again for your help.

:smile:

@peekay123, learnt something new today!!:slight_smile:

My whole code is in this gist,
https://gist.github.com/JulianPlant524/3d88fb6d37918df0372e

I have tried swapping the include application.h to the top. This does not help.

I don’t understand why the error checker pull up at line 35 strip.setPixelColor(sec,50,50,50); saying that strip was not defined when it has already gone past strip.setBrightness(); strip.show(); etc. I assume that it compiles from top to bottom in order.

neopixel_clock.cpp:35:1: error: ‘strip’ was not declared in this scope.

Any help greatly appreciated. This is not super urgent or important but I am curious to know what is going on.

Cheers,

@peekay123, @delianides,

Ok so tonight I deleted the old code and started again. Got the neopixel example up and running and the cut and re-wrote bits in from there. All working fine now. Thank you very much for your head scratching and help. Lesson learnt. If it is not working, start again from where it did last work.

Cheers.

1 Like

@Julian, good work! :wink:

1 Like