mirror of
https://gitlab.com/wirelos/sprocket-plugin-gpio.git
synced 2025-12-14 13:26:48 +01:00
combined example
This commit is contained in:
@@ -47,4 +47,15 @@ upload_speed = ${common.upload_speed}
|
||||
monitor_baud = ${common.monitor_baud}
|
||||
src_filter = +<*> -<examples/> +<examples/rotary/> -<inputs/> +<inputs/rotary>
|
||||
lib_deps = ${common.lib_deps}
|
||||
Ai Esp32 Rotary Encoder
|
||||
Ai Esp32 Rotary Encoder
|
||||
|
||||
[env:combined_esp32]
|
||||
platform = espressif32
|
||||
board = esp32dev
|
||||
framework = ${common.framework}
|
||||
build_flags = -std=c++14
|
||||
upload_speed = ${common.upload_speed}
|
||||
monitor_baud = ${common.monitor_baud}
|
||||
src_filter = +<*> +<inputs/pot> +<inputs/rotary> -<examples/> +<examples/combined/>
|
||||
lib_deps = ${common.lib_deps}
|
||||
Ai Esp32 Rotary Encoder
|
||||
31
src/examples/combined/config.h
Normal file
31
src/examples/combined/config.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#ifndef __DEVICE_CONFIG__
|
||||
#define __DEVICE_CONFIG__
|
||||
|
||||
// Scheduler
|
||||
#define _TASK_SLEEP_ON_IDLE_RUN
|
||||
#define _TASK_STD_FUNCTION
|
||||
#define _TASK_PRIORITY
|
||||
|
||||
// Chip
|
||||
#define SPROCKET_TYPE "SPROCKET"
|
||||
#define SERIAL_BAUD_RATE 115200
|
||||
#define STARTUP_DELAY 1000
|
||||
|
||||
/*
|
||||
connecting Rotary encoder
|
||||
CLK (A pin) - to any microcontroler intput pin with interrupt
|
||||
DT (B pin) - to any microcontroler intput pin with interrupt
|
||||
SW (button pin) - to any microcontroler intput pin
|
||||
VCC - to microcontroler VCC (then set ROTARY_ENCODER_VCC_PIN -1)
|
||||
GND - to microcontroler GND
|
||||
*/
|
||||
#define ROTARY_ENCODER_A_PIN 35
|
||||
#define ROTARY_ENCODER_B_PIN 34
|
||||
#define ROTARY_ENCODER_BUTTON_PIN 21
|
||||
#define ROTARY_ENCODER_VCC_PIN -1 /*put -1 of Rotary encoder Vcc is connected directly to 3,3V; else you can use declared output pin for powering rotary encoder */
|
||||
|
||||
// Pot
|
||||
#define POT_THRESHOLD 16
|
||||
#define POT_POLL_INTERVAL 50
|
||||
|
||||
#endif
|
||||
44
src/examples/combined/main.cpp
Normal file
44
src/examples/combined/main.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
#include "config.h"
|
||||
#include "Sprocket.h"
|
||||
#include "inputs/rotary/RotaryPlugin.h"
|
||||
#include "inputs/pot/PotPlugin.h"
|
||||
|
||||
Sprocket *sprocket;
|
||||
RotaryPlugin *r1;
|
||||
PotPlugin* p1;
|
||||
|
||||
void addRotary(Sprocket *s, Plugin *r, const char *topic)
|
||||
{
|
||||
String btnTopic = String(topic) + String("/button");
|
||||
s->subscribe(topic, bind([](String label, String val) { PRINT_MSG(Serial, label.c_str(), val.c_str()); }, topic, _1));
|
||||
s->subscribe(btnTopic, bind([](String label, String val) { PRINT_MSG(Serial, label.c_str(), val.c_str()); }, btnTopic, _1));
|
||||
s->addPlugin(r);
|
||||
}
|
||||
|
||||
void addPot(Sprocket* s, int pin, const char* topic)
|
||||
{
|
||||
s->addPlugin(
|
||||
new PotPlugin({pin, POT_THRESHOLD, POT_POLL_INTERVAL, topic}));
|
||||
s->subscribe(topic, bind([](String label, String val){
|
||||
PRINT_MSG(Serial, label.c_str(), val.c_str());
|
||||
}, topic, _1));
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
sprocket = new Sprocket({STARTUP_DELAY, SERIAL_BAUD_RATE});
|
||||
r1 = new RotaryPlugin({35, 34, 21, -1, 50, 0, 255, true, "rotary1"});
|
||||
r1->rotaryEncoder->setup([] { r1->rotaryEncoder->readEncoder_ISR(); });
|
||||
addRotary(sprocket, r1, "rotary1");
|
||||
addPot(sprocket, 36, "pot1");
|
||||
addPot(sprocket, 37, "pot2");
|
||||
addPot(sprocket, 38, "pot3");
|
||||
addPot(sprocket, 39, "pot4");
|
||||
sprocket->activate();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
sprocket->loop();
|
||||
yield();
|
||||
}
|
||||
@@ -8,9 +8,9 @@ RotaryPlugin *r1;
|
||||
void addRotary(Sprocket *s, Plugin *r, const char *topic)
|
||||
{
|
||||
String btnTopic = String(topic) + String("/button");
|
||||
s->addPlugin(r);
|
||||
s->subscribe(topic, bind([](String label, String val) { PRINT_MSG(Serial, label.c_str(), val.c_str()); }, topic, _1));
|
||||
s->subscribe(btnTopic, bind([](String label, String val) { PRINT_MSG(Serial, label.c_str(), val.c_str()); }, btnTopic, _1));
|
||||
s->addPlugin(r);
|
||||
}
|
||||
|
||||
void setup()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef __POT_PLUGIN_H__
|
||||
#define __POT_PLUGIN_H__
|
||||
#ifndef __ROTARY_PLUGIN_H__
|
||||
#define __ROTARY_PLUGIN_H__
|
||||
|
||||
#define _TASK_SLEEP_ON_IDLE_RUN
|
||||
#define _TASK_STD_FUNCTION
|
||||
|
||||
Reference in New Issue
Block a user