FastLED 3.9.15
Loading...
Searching...
No Matches
ui_state.cpp
Go to the documentation of this file.
1#include "../shared/defs.h"
2
3
4#if ENABLE_SKETCH
5
6
7#include "./ui_state.h"
8#include "shared/Painter.h"
9#include "fl/dbg.h"
10#include "fl/unused.h"
11
12#include <Arduino.h>
13
14//#define UI_V1 // Based off the old midi shield with hand assmebled buttons.
15#define UI_V2 // Based on a new midi shield with buttons. https://learn.sparkfun.com/tutorials/midi-shield-hookup-guide
16#define UI_DBG
17
18
19#ifndef A3
20#define A3 3
21#warning "A3 is not defined, using 3"
22#endif
23#ifndef A4
24#define A4 4
25#warning "A4 is not defined, using 4"
26#endif
27
28#ifdef __STM32F1__
29// Missing A-type pins, just use digital pins mapped to analog.
30#define PIN_POT_COLOR_SENSOR D3
31#define PIN_POT_VEL_SENSOR D4
32#else
33#define PIN_POT_COLOR_SENSOR A3
34#define PIN_POT_VEL_SENSOR A4
35#endif
36
37#define PIN_VIS_SELECT 2
38#define PIN_COLOR_SELECT 4
39
40Potentiometer velocity_pot(PIN_POT_VEL_SENSOR);
41Potentiometer color_pot(PIN_POT_COLOR_SENSOR);
42
43float read_color_selector() {
44 return color_pot.Read();
45}
46
47float read_velocity_bias() {
48 return velocity_pot.Read();
49}
50
51
52//DigitalButton custom_notecolor_select(4);
53ColorSelector color_selector(PIN_COLOR_SELECT);
54CountingButton vis_selector(PIN_VIS_SELECT);
55
56void ui_init() {
57}
58
59
60ui_state ui_update(uint32_t now_ms, uint32_t delta_ms) {
61 FL_UNUSED(delta_ms);
62
63 ui_state out;
64 vis_selector.Update(now_ms);
65 color_selector.Update();
66 int32_t curr_val = vis_selector.curr_val();
67 FASTLED_DBG("curr_val: " << curr_val);
68
69 out.color_scheme = color_selector.curr_val();
70
71 //bool notecolor_on = custom_notecolor_select.Read();
72
73 //Serial.print("color selector: "); Serial.println(out.color_scheme);
74
75 //float velocity = read_velocity_bias();
76 //float color_selector = read_color_selector();
77
78 //Serial.print("velocity: "); Serial.print(velocity); Serial.print(", color_selector: "); Serial.print(color_selector);
79
80 //if (notecolor_on) {
81 // Serial.print(", notecolor_on: "); Serial.print(notecolor_on);
82 //}
83
84 //Serial.print("color_scheme: "); Serial.print(out.color_scheme); Serial.print(", vis selector: "); Serial.print(curr_val);
85
86 //Serial.println("");
87
88 //Serial.print("curr_val: "); Serial.print(curr_val);// Serial.print(", button state: "); Serial.println(vis_selector.button_.curr_val());;
89
90 out.which_visualizer = static_cast<Painter::VisState>(curr_val % Painter::kNumVisStates);
91 return out;
92}
93
94
95#endif // ENABLE_SKETCH
#define FASTLED_DBG(X)
Definition dbg.h:61
@ kNumVisStates
Definition Painter.h:21
int which_visualizer
Definition ui_state.h:13
int color_scheme
Definition ui_state.h:14
ui_state ui_update(uint32_t now_ms, uint32_t delta_ms)
void ui_init()
ColorSelector color_selector
CountingButton vis_selector
#define FL_UNUSED(x)
Definition unused.h:8