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 a "not found" message 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? I've brought it up in the Particle.io forums as well an, so far, the consensus has been that the microcontroller is plenty speedy at these things, so it's likely the App Inventor. Below are the blocks of my app and below that is the Particle-specific arduino sketch.
// 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 = 1;
int addStart(String command);
int subStart(String command);
int addEnd(String command);
int subEnd(String command);
int doUpdate(String command);
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);
updateStrip();
FastLED.show();
Particle.variable("startLit", startLit);
Particle.variable("endLit", endLit);
Particle.function("doUpdate", doUpdate);
}
void loop() {
}
int doUpdate(String command){
if(command=="addStart"){
if(startLit<endLit){
startLit++;
}
}else if(command=="subStart"){
if(startLit>=0){
startLit--;
}
}else if(command=="addEnd"){
if(endLit<NUM_LEDS-1){
endLit++;
}
}else if(command=="subEnd"){
if(endLit>startLit){
endLit--;
}
}
updateStrip();
return 1;
}
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();
}