Hoping someone has a moment to look at this.
I’m using a Photon to control an LED strip. To help map out patterns and such, I’m trying to write a VERY simple sketch that increases or decreases the number of LEDs lit by adjusting start and end values updated by button taps from a MIT App Inventor project.
The app has 5 buttons: Start -, Start +, End -, End +, Refresh. The first 4 increase or decrease the head or tail of the section of LEDs and that works great. From there, I added two text fields that, via a GET operation, reads the values exposed on the device. In this case: startLit and endLit. The Refresh button executes the GET, reads the values and updates the two text fields. Again, this seems to work really well. The command even works to get the values with no hiccups as the screen initializes on the phone.
Where it starts to get hairy is when I try to add the GET function to pull the values immediately after the POST function changes the value. Sometimes it works. More often though I either get an error or nothing happens, even though the values have indeed increased and I can see that properly if I hit the Refresh button. Should I expect a reasonable amount of delay in communications between a POST and a GET function? At first I thought it was an issue with the app’s block structure, but I’m starting to think it’s Particle related.
// This #include statement was automatically added by the Particle IDE.
//#define FASTLED_ALLOW_INTERRUPTS 0
#include <FastLED.h>
#include "Particle.h"
/*
LED Map
*/
FASTLED_USING_NAMESPACE;
#define LED_PIN D4
#define COLOR_ORDER GRB
#define CHIPSET WS2812B
#define NUM_LEDS 300 //88 for testing, 300 for prodction
#define BRIGHTNESS 200
#define FRAMES_PER_SECOND 24
int startLit = 0;
int endLit = 0;
NSFastLED :: CRGB leds[NUM_LEDS];
void setup() {
delay(3000); // sanity delay
FastLED.addLeds<CHIPSET, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
FastLED.setBrightness( 10 );
FastLED.clear();
fill_solid(leds,NUM_LEDS,CRGB::Black);
//leds[0] = CHSV(255,255,255);
set_max_power_in_volts_and_milliamps(5, 1000);
FastLED.show();
Particle.variable("startLit", startLit);
Particle.variable("endLit", endLit);
Particle.function("startUpdate", startUpdate);
Particle.function("endUpdate", endUpdate);
Particle.function("addStart", addStart);
Particle.function("subStart", subStart);
Particle.function("addEnd", addEnd);
Particle.function("subEnd", subEnd);
}
void loop() {
}
int addStart(String i){
if(startLit<endLit){
startLit++;
}
updateStrip();
}
int subStart(String i){
if(startLit>=0){startLit--;}
updateStrip();
}
int addEnd(String i){
if(endLit<NUM_LEDS-1){endLit++;}
updateStrip();
}
int subEnd(String i){
if(endLit>startLit){endLit--;}
updateStrip();
}
int startUpdate(String newStart){
startLit = newStart.toInt();
updateStrip();
}
int endUpdate(String newEnd){
endLit = newEnd.toInt();
updateStrip();
}
void updateStrip(){
for(int i=0;i<NUM_LEDS;i++){
if((i>=startLit) && (i<=endLit)){
leds[i] = CHSV(255,255,255);
}else{
leds[i] = CHSV(0,0,0);
}
}
FastLED.show();
}