Reduced cap touch sampling to fix performance
#include "globals.h"
+static uint32_t lastTouchSample;
static uint32_t lastBehaviorChange;
static uint32_t lastWave;
@@ -10,6 +11,7 @@ static int currentBehavior = 0;
static int colorIndex = 0;
const uint32_t SAMPLE_TIME = 50000;
+const uint32_t TOUCH_SAMPLE_TIME = SAMPLE_TIME * 15;
static uint8_t currentStep = 100;
static int direction = -3;
static uint32_t lastColorShift;
@@ -50,6 +52,10 @@ void setGradientPixelColor(uint16_t ledPosition, uint16_t step, float redRatio,
arcada.pixels.setPixelColor(ledPosition, red, green, blue);
}
+void stepGreenBlackGradient(uint16_t ledPosition, uint16_t step) {
+ setGradientPixelColor(ledPosition, step, 0, 1, 0);
+}
+
void stepOrangeBlackGradient(uint16_t ledPosition, uint16_t step) {
setGradientPixelColor(ledPosition, step, 1, 0.64453125, 0);
}
@@ -233,17 +239,19 @@ void changeBehavior(int newBehavior, uint32_t timeOfChange) {
}
void user_setup(void) {
- lastBehaviorChange, lastWave, lastColorShift, lastRainbowColorShift = micros();
+ lastBehaviorChange, lastWave, lastColorShift, lastRainbowColorShift, lastTouchSample = micros();
arcada.pixels.setBrightness(255);
advanceHalloweenGradients();
changeBehavior(0, micros());
}
void user_loop(void) {
+ uint32_t elapsedSince = micros();
+ if(elapsedSince - lastTouchSample > TOUCH_SAMPLE_TIME) {
+ lastTouchSample = elapsedSince;
uint8_t pressed_buttons = arcada.readButtons();
uint8_t justpressed_buttons = arcada.justPressedButtons();
- uint32_t elapsedSince = micros();
if (justpressed_buttons & ARCADA_BUTTONMASK_UP){
changeBehavior(0, elapsedSince);
}
@@ -256,6 +264,7 @@ void user_loop(void) {
else if(justpressed_buttons & ARCADA_BUTTONMASK_RIGHT) {
changeBehavior(3, elapsedSince);
}
+ }
if (elapsedSince - lastWave > SAMPLE_TIME) {
lastWave = elapsedSince;
