Hi all!
I've been using a Circuit Playground in conjunction with the Arduino IDE and there's an issue I've been running into I can't seem to figure out.
I'm trying to use the onboard accelerometer of the CPB to activate different lights. Specifically I want it to store the time when the accelerometer recorded a reading less than -12 across the X-axis, add 1000 to it (or some other predetermined time), and compare that number with the current time. If the difference is greater than -1 I want it to set the neopixels white. Later I'm going to incorporate a loop function that will continually diminish the brightness and then return to a different function.
The issue I'm running into is that it records the time I flicked the device, but almost immediately returns this massive number that must be an error code or place holder for something and in the process continually sets the neopixels white. A picture is below.
Any help would be greatly appreciated! Please let me know if anything is confusing about my post!
#include <Adafruit_CircuitPlayground.h>
void setup() {
Serial.begin(115200);
Serial.println("Circuit Playground Connected!");
CircuitPlayground.begin();
}
void loop() {
float X = CircuitPlayground.motionX(); //store X-axis accelerometer data as float X
unsigned long waitTime = 1000; //used as easily changeable value; added to stored time
unsigned long myTime; // stores controller's time
unsigned long deviceTime = millis(); // time since program started
CircuitPlayground.setBrightness(50); // neopixel brightness level
if (X < -12) { // if X-axis accelerometer is less than -12
myTime = deviceTime + waitTime; // store current controller time and add waitTime
}
Serial.println(myTime); //print value stored in myTime every 50ms; just for checking purposes
delay(50);
if (myTime - deviceTime >= 0) { // if the stored time is greater than the device's time set device neopixels to white until timer runs out
CircuitPlayground.setPixelColor(0, 255, 255, 255);
CircuitPlayground.setPixelColor(1, 255, 255, 255);
CircuitPlayground.setPixelColor(2, 255, 255, 255);
CircuitPlayground.setPixelColor(3, 255, 255, 255);
CircuitPlayground.setPixelColor(4, 255, 255, 255);
CircuitPlayground.setPixelColor(5, 255, 255, 255);
CircuitPlayground.setPixelColor(6, 255, 255, 255);
CircuitPlayground.setPixelColor(7, 255, 255, 255);
CircuitPlayground.setPixelColor(8, 255, 255, 255);
CircuitPlayground.setPixelColor(9, 255, 255, 255);
} else { //if stored time is less than device time set neopixels to blue
CircuitPlayground.setPixelColor(0, 0, 255, 255);
CircuitPlayground.setPixelColor(1, 0, 255, 255);
CircuitPlayground.setPixelColor(2, 0, 255, 255);
CircuitPlayground.setPixelColor(3, 0, 255, 255);
CircuitPlayground.setPixelColor(4, 0, 255, 255);
CircuitPlayground.setPixelColor(5, 0, 255, 255);
CircuitPlayground.setPixelColor(6, 0, 255, 255);
CircuitPlayground.setPixelColor(7, 0, 255, 255);
CircuitPlayground.setPixelColor(8, 0, 255, 255);
CircuitPlayground.setPixelColor(9, 0, 255, 255);
}
}
