Skip to content

Commit

Permalink
Revert "added rotary encoder code"
Browse files Browse the repository at this point in the history
This reverts commit df9e16c.
  • Loading branch information
shillinc-osu committed May 12, 2024
1 parent df9e16c commit e8e0d43
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 74 deletions.
67 changes: 3 additions & 64 deletions main/main.ino
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "ext_analysis.h"
#include "storage.h"
#include "globals.h"
#include "AiEsp32RotaryEncoder.h"


FASTLED_USING_NAMESPACE

Expand Down Expand Up @@ -74,9 +74,6 @@ uint8_t manual_pattern_idx = 0;
/// Contains if manual control is enabled or not.
volatile bool manual_control_enabled = false;

/// The current rotary encoder pattern index.
uint8_t rotary_encoder_pattern_idx = 0;

/// History of all currently-running subpatterns.
Pattern_History histories[NUM_SUBPATTERNS];

Expand All @@ -92,48 +89,6 @@ extern Pattern mainPatterns[];
#include "api.h"
#endif

AiEsp32RotaryEncoder rotaryEncoder = AiEsp32RotaryEncoder(ROTARY_ENCODER_A_PIN,
ROTARY_ENCODER_B_PIN,
ROTARY_ENCODER_BUTTON_PIN,
ROTARY_ENCODER_VCC_PIN,
ROTARY_ENCODER_STEPS);

void rotary_onButtonClick()
{
static unsigned long lastTimePressed = 0; // Soft debouncing
if (millis() - lastTimePressed < 500)
{
return;
}
lastTimePressed = millis();
Serial.print("button pressed ");
Serial.print("hello world1 ");

Serial.print(millis());
Serial.println(" milliseconds after restart");
}
void rotary_loop()
{
//dont print anything unless value changed
if (rotaryEncoder.encoderChanged())
{
Serial.print("Value: ");

rotary_encoder_pattern_idx = rotaryEncoder.readEncoder();
Serial.println(rotaryEncoder.readEncoder());
nextPattern();
}
if (rotaryEncoder.isEncoderButtonClicked())
{
rotary_onButtonClick();
}
}
void IRAM_ATTR readEncoderISR()
{
rotaryEncoder.readEncoder_ISR();
}


void setup();
void loop();
void audio_analysis();
Expand All @@ -149,22 +104,6 @@ void setup() {
// Start USB serial communication
Serial.begin(115200);
while (!Serial) { ; }
Serial.print("hello world3 ");

//Initialize rotary encoder
rotaryEncoder.begin();
rotaryEncoder.setup(readEncoderISR);
bool circleValues = true;
rotaryEncoder.setBoundaries(0, 40, circleValues); //minValue, maxValue, circleValues true|false (when max go to min and vice versa)

/*Rotary acceleration introduced 25.2.2021.
in case range to select is huge, for example - select a value between 0 and 1000 and we want 785
without accelerateion you need long time to get to that number
Using acceleration, faster you turn, faster will the value raise.
For fine tuning slow down.
*/
//rotaryEncoder.disableAcceleration(); //acceleration is now enabled by default - disable if you dont need it
rotaryEncoder.setAcceleration(250); //or set the value - larger number = more accelearation; 0 or 1 means disabled acceleration

// Reindex mainPatterns, to make sure it is consistent.
for (int i = 0; i < NUM_PATTERNS; i++) {
Expand Down Expand Up @@ -343,7 +282,7 @@ void print_buffer(CRGB *buf, uint8_t len) {
for (int i = 0; i < len; i++) {
Serial.print(String(buf[i].r) + "," + String(buf[i].g) + "," + String(buf[i].b) + " ");
}
// Serial.print("\n");
Serial.print("\n");
}

/// @brief Runs the main program loop.
Expand All @@ -353,7 +292,7 @@ void print_buffer(CRGB *buf, uint8_t len) {
void loop() {

begin_loop_timer(config.loop_ms); // Begin timing this loop
rotary_loop();

// Reset buffers if pattern settings were changed since
// last program loop.
if (pattern_changed) {
Expand Down
7 changes: 0 additions & 7 deletions main/nanolux_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,6 @@ typedef void (*SimplePatternList[])();
// Array size macro
#define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))

// Rotary Encoder
#define ROTARY_ENCODER_A_PIN 23
#define ROTARY_ENCODER_B_PIN 22
#define ROTARY_ENCODER_BUTTON_PIN 33
#define ROTARY_ENCODER_VCC_PIN -1
#define ROTARY_ENCODER_STEPS 4

// FastLED
#define MAX_LEDS 200
#define DATA_PIN 15 // No hardware SPI pins defined for the ESP32 yet.
Expand Down
4 changes: 1 addition & 3 deletions main/patterns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include "core_analysis.h"
#include "ext_analysis.h"
#include "palettes.h"
#include "AiEsp32RotaryEncoder.h"

extern unsigned long microseconds;
extern double vReal[SAMPLES]; // Sampling buffers
Expand All @@ -41,12 +40,11 @@ bool gReverseDirection = false;
extern Config_Data config; // Currently loaded config
extern uint8_t manual_pattern_idx;
extern volatile bool manual_control_enabled;
extern uint8_t rotary_encoder_pattern_idx;

void nextPattern() {
// add one to the current pattern number, and wrap around at the end
if(manual_control_enabled){
manual_pattern_idx = (rotary_encoder_pattern_idx) % NUM_PATTERNS;
manual_pattern_idx = (manual_pattern_idx + 1) % NUM_PATTERNS;
}else{
manual_control_enabled = true;
}
Expand Down

0 comments on commit e8e0d43

Please sign in to comment.