Hello all,
I have a small code which makes a LED ring light up in rainbow colors as long as a sensor is touched.
// FastLED - Version: Latest
#include <FastLED.h>
#define NUM_LEDS 24
#define DATA_PIN 12
CRGB leds[NUM_LEDS];
// CapacitiveSensor - Version: Latest
#include <CapacitiveSensor.h>
CapacitiveSensor sensor = CapacitiveSensor(2,10);
uint8_t hue;
void setup() {
Serial.begin(9600);
delay(1500);
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
FastLED.clear();
FastLED.show();
}
void loop() {
while(isTouching()) {
Serial.println(hue);
fill_solid(leds, NUM_LEDS, CHSV(hue, 255, 255));
FastLED.show();
hue++;
delay(50);
}
delay(50);
}
boolean isTouching() {
if(sensor.capacitiveSensor(30) > 5000) return true;
return false;
}
This code works 100% when uploaded to the Nano 33 IoT using the Arudino IDE.
Now I tried to implement the same code using the IoT Cloud (to match colors later for example).
// FastLED - Version: Latest
#include <FastLED.h>
#define NUM_LEDS 24
#define DATA_PIN 12
CRGB leds[NUM_LEDS];
// CapacitiveSensor - Version: Latest
#include <CapacitiveSensor.h>
#include "thingProperties.h"
CapacitiveSensor sensor = CapacitiveSensor(2,10);
uint8_t hue;
void setup() {
Serial.begin(9600);
delay(1500);
initProperties();
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
setDebugMessageLevel(4);
ArduinoCloud.printDebugInfo();
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
FastLED.clear();
FastLED.show();
}
void loop() {
ArduinoCloud.update();
while(isTouching()) {
Serial.println(hue);
fill_solid(leds, NUM_LEDS, CHSV(hue, 255, 255));
FastLED.show();
hue++;
delay(50);
}
delay(50);
}
boolean isTouching() {
if(sensor.capacitiveSensor(30) > 5000) return true;
return false;
}
Unfortunately, this code no longer works when uploaded to the Nano 33 IoT via the IoT Cloud.
The output in the Serial Monitor shows numbers from 0-255, then from 0 to about 20 and then the Arduino just restarts.
Why does the Nano 33 IoT restart every time it uses the IoT Cloud? How can I work around this?