Skip to content

Commit 6be8e7e

Browse files
committed
2 parents 40fbbb3 + 7e717e1 commit 6be8e7e

1 file changed

Lines changed: 24 additions & 15 deletions

File tree

M4_Eyes/user_touchneopixels.cpp

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "globals.h"
44

5+
static uint32_t lastTouchSample;
56
static uint32_t lastBehaviorChange;
67
static uint32_t lastWave;
78

@@ -10,6 +11,7 @@ static int currentBehavior = 0;
1011
static int colorIndex = 0;
1112

1213
const uint32_t SAMPLE_TIME = 50000;
14+
const uint32_t TOUCH_SAMPLE_TIME = SAMPLE_TIME * 15;
1315
static uint8_t currentStep = 100;
1416
static int direction = -3;
1517
static uint32_t lastColorShift;
@@ -50,6 +52,10 @@ void setGradientPixelColor(uint16_t ledPosition, uint16_t step, float redRatio,
5052
arcada.pixels.setPixelColor(ledPosition, red, green, blue);
5153
}
5254

55+
void stepGreenBlackGradient(uint16_t ledPosition, uint16_t step) {
56+
setGradientPixelColor(ledPosition, step, 0, 1, 0);
57+
}
58+
5359
void stepOrangeBlackGradient(uint16_t ledPosition, uint16_t step) {
5460
setGradientPixelColor(ledPosition, step, 1, 0.64453125, 0);
5561
}
@@ -233,28 +239,31 @@ void changeBehavior(int newBehavior, uint32_t timeOfChange) {
233239
}
234240

235241
void user_setup(void) {
236-
lastBehaviorChange, lastWave, lastColorShift, lastRainbowColorShift = micros();
242+
lastBehaviorChange, lastWave, lastColorShift, lastRainbowColorShift, lastTouchSample = micros();
237243
arcada.pixels.setBrightness(255);
238244
advanceHalloweenGradients();
239245
changeBehavior(0, micros());
240246
}
241247

242248
void user_loop(void) {
243-
uint8_t pressed_buttons = arcada.readButtons();
244-
uint8_t justpressed_buttons = arcada.justPressedButtons();
245-
246249
uint32_t elapsedSince = micros();
247-
if (justpressed_buttons & ARCADA_BUTTONMASK_UP){
248-
changeBehavior(0, elapsedSince);
249-
}
250-
else if(justpressed_buttons & ARCADA_BUTTONMASK_DOWN) {
251-
changeBehavior(1, elapsedSince);
252-
}
253-
else if(justpressed_buttons & ARCADA_BUTTONMASK_LEFT) {
254-
changeBehavior(2, elapsedSince);
255-
}
256-
else if(justpressed_buttons & ARCADA_BUTTONMASK_RIGHT) {
257-
changeBehavior(3, elapsedSince);
250+
if(elapsedSince - lastTouchSample > TOUCH_SAMPLE_TIME) {
251+
lastTouchSample = elapsedSince;
252+
uint8_t pressed_buttons = arcada.readButtons();
253+
uint8_t justpressed_buttons = arcada.justPressedButtons();
254+
255+
if (justpressed_buttons & ARCADA_BUTTONMASK_UP){
256+
changeBehavior(0, elapsedSince);
257+
}
258+
else if(justpressed_buttons & ARCADA_BUTTONMASK_DOWN) {
259+
changeBehavior(1, elapsedSince);
260+
}
261+
else if(justpressed_buttons & ARCADA_BUTTONMASK_LEFT) {
262+
changeBehavior(2, elapsedSince);
263+
}
264+
else if(justpressed_buttons & ARCADA_BUTTONMASK_RIGHT) {
265+
changeBehavior(3, elapsedSince);
266+
}
258267
}
259268

260269
if (elapsedSince - lastWave > SAMPLE_TIME) {

0 commit comments

Comments
 (0)