Was working on Weasley clock but original 25 LED string wouldn’t work properly with code. Took the system offline for a month while waiting on 50 light string to be delivered. I tried to push the old code to my Photon last night but get an error when verifying stating " error: ‘number_for_key’ was not declared in this scope".
As mentioned, this is the exact same code so I’m unsure why I am suddenly getting this error. What would something have changed on the Particle end in the past month which would effect this?
This is the code I am using.
// This #include statement was automatically added by the Particle IDE.
#include "neopixel/neopixel.h"
#include <stdio.h>
#include <string.h>
#include <math.h>
#define PIXEL_COUNT 50
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, D3, WS2812B);
int brite = 3;
struct entry {
String str;
int n;
};
struct entry places[] = { //After the first letter and a space, write this word in IFTTT
"home", 1,
"work", 2,
"prison", 3,
"cottage", 4,
"mortal", 5,
"transit", 6,
0,0
};
struct entry people[] = { //This letter should be first character in IFTTT
"C", 1,
"S", 2,
"A", 3,
"R", 4,
"Y", 5,
"Z", 6,
0,0
};
struct entry colors[] = { //Defines the color for each name.
"C", 0xffff00,
"S", 0xff0000,
"A", 0x00ff00,
"R", 0x00ff80,
"Y", 0xff00ff,
"Z", 0x0000ff,
0,0
};
//name=people=capitalized letters
int updateClock(String command) {
int commaIndex = command.indexOf(' '); //locate the space
int secondCommaIndex = command.indexOf(' ', commaIndex+1); //locate the second space, starting one character after the first space
String name = command.substring(0, commaIndex); //name's value is the string starting at the beginning and ending before the space
String loc = command.substring(commaIndex+1, secondCommaIndex); //loc's value is the string starting after the space and ending before the second space
int person = number_for_key(name, people); //check for match between the string, name, and people then record the number of the person
if(person != 0){
flashB(number_for_key(name, colors)); //send color code to flash B for name
int place = number_for_key(loc, places);
if(place != 0){
allMineOff(person);
int personcolor = number_for_key(name, colors);
int red = floor(personcolor / (256*256));
int green = (int)floor(personcolor / 256) % 256;
int blue = personcolor % 256;
strip.setPixelColor(7+person+6*place, strip.Color(green, red, blue));
strip.show();
}
}
return 1;
}
void setup() {
Particle.function("updateClock", updateClock);
//pinMode(buttonPin, INPUT);
strip.begin();
strip.show();
startupSwirl();
strip.setBrightness(80);
allOff();
for(int j=1; j<=6; j++) { // set everyone to home
strip.setPixelColor(7+j+6*4, strip.Color(255, 255, 255));
}
}
void loop() {
strip.show();
strip.setBrightness(50);
}
int number_for_key(String key, struct entry dict[]){ //checks the given name with the list of names allowed, returns number of match
for(int j=0; j<6; j++) {
String name = dict[j].str;
if (strcmp(name, key) == 0)
return dict[j].n;
}
return 0;
}
//This swirl is just for flashiness, only occurs on start up.
void startupSwirl() { // outer hands counterclockwise, inner hands clockwise
int swirldelay = 50;
for(int j=0; j<2; j++) {
for(int i=14; i<50; i+=3) {
allOff();
strip.setPixelColor(i, strip.Color(255, 255, 255));
strip.setPixelColor(62-i, strip.Color(255, 255, 255));
strip.show();
delay(swirldelay);
allOff();
strip.setPixelColor(i+2, strip.Color(255, 255, 255));
strip.setPixelColor(62-i, strip.Color(255, 255, 255));
strip.show();
delay(swirldelay);
}
}
}
void flashB(int hexValue){
int red = floor(hexValue / (256*256));
int green = (int)floor(hexValue / 256) % 256;
int blue = hexValue % 256;
for(int j=0; j<5; j++) {
for(int i=0; i<14; i++) {
strip.setPixelColor(i, strip.Color(green, red, blue));
}
strip.show();
delay(300);
for(int i=0; i<14; i++) {
strip.setPixelColor(i, strip.Color(0,0,0));
}
strip.show();
delay(300);
}
}
void allMineOff(int n) {
for(int i=7+n; i<PIXEL_COUNT; i+=6) {
strip.setPixelColor(i, strip.Color(0, 0, 0));
}
strip.show();
}
void allOff() {
for(int i=0; i<PIXEL_COUNT; i++) {
strip.setPixelColor(i, strip.Color(0, 0, 0));
}
strip.show();
}