mirror of
https://gitlab.com/wirelos/sprocket-plugin-gpio.git
synced 2025-12-14 05:16:50 +01:00
blaah*
This commit is contained in:
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"terminal.integrated.env.linux": {
|
||||
"PATH": "/home/master/.platformio/penv/bin:/home/master/.platformio/penv:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl",
|
||||
"PATH": "/home/master/.platformio/penv/bin:/home/master/.platformio/penv:/home/master/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/sbin:/usr/sbin",
|
||||
"PLATFORMIO_CALLER": "vscode"
|
||||
},
|
||||
"files.associations": {
|
||||
|
||||
1
lib/a21
Submodule
1
lib/a21
Submodule
Submodule lib/a21 added at 9db8a9b4b1
@@ -23,8 +23,6 @@ upload_speed = ${common.upload_speed}
|
||||
monitor_baud = ${common.monitor_baud}
|
||||
src_filter = +<*> -<examples/> +<examples/analog/> -<inputs/> +<inputs/analog>
|
||||
lib_deps = ${common.lib_deps}
|
||||
lib_ignore =
|
||||
Ai Esp32 Rotary Encoder
|
||||
|
||||
[env:pir]
|
||||
platform = ${common.platform}
|
||||
@@ -35,8 +33,6 @@ monitor_baud = ${common.monitor_baud}
|
||||
build_flags = -DSPROCKET_PRINT=1
|
||||
src_filter = +<*> -<examples/> +<examples/pir/> -<inputs/> +<inputs/pir> +<inputs/digital>
|
||||
lib_deps = ${common.lib_deps}
|
||||
lib_ignore =
|
||||
Ai Esp32 Rotary Encoder
|
||||
|
||||
[env:audio]
|
||||
platform = ${common.platform}
|
||||
@@ -46,8 +42,6 @@ upload_speed = ${common.upload_speed}
|
||||
monitor_baud = ${common.monitor_baud}
|
||||
src_filter = +<*> -<examples/> +<examples/audio/> -<inputs/> +<inputs/audio>
|
||||
lib_deps = ${common.lib_deps}
|
||||
lib_ignore =
|
||||
Ai Esp32 Rotary Encoder
|
||||
|
||||
[env:analog_esp32]
|
||||
platform = espressif32
|
||||
@@ -58,8 +52,17 @@ upload_speed = ${common.upload_speed}
|
||||
monitor_baud = ${common.monitor_baud}
|
||||
src_filter = +<*> -<examples/> +<examples/analog/> -<inputs/> +<inputs/analog>
|
||||
lib_deps = ${common.lib_deps}
|
||||
lib_ignore =
|
||||
Ai Esp32 Rotary Encoder
|
||||
|
||||
[env:rotary_ec11]
|
||||
platform = ${common.platform}
|
||||
board = ${common.board}
|
||||
framework = ${common.framework}
|
||||
upload_speed = ${common.upload_speed}
|
||||
monitor_baud = ${common.monitor_baud}
|
||||
src_filter = +<*> -<examples/> +<examples/rotary/> -<inputs/> +<inputs/rotary>
|
||||
lib_deps = ${common.lib_deps}
|
||||
lib_ignore = Ai Esp32 Rotary Encoder
|
||||
|
||||
|
||||
[env:rotary_esp32]
|
||||
platform = espressif32
|
||||
@@ -69,8 +72,6 @@ build_flags = -std=c++14
|
||||
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
|
||||
|
||||
[env:combined_esp32]
|
||||
platform = espressif32
|
||||
@@ -81,4 +82,3 @@ upload_speed = ${common.upload_speed}
|
||||
monitor_baud = ${common.monitor_baud}
|
||||
src_filter = +<*> +<inputs/analog> +<inputs/rotary> -<examples/> +<examples/combined/>
|
||||
lib_deps = ${common.lib_deps}
|
||||
Ai Esp32 Rotary Encoder
|
||||
@@ -1,29 +1,100 @@
|
||||
#include "config.h"
|
||||
#include "Sprocket.h"
|
||||
#include "inputs/rotary/RotaryPlugin.h"
|
||||
|
||||
Sprocket *sprocket;
|
||||
RotaryPlugin *r1;
|
||||
//
|
||||
// a21 — Arduino Toolkit. Example for EC11 class.
|
||||
// Copyright (C) 2016-2017, Aleh Dzenisiuk. http://github.com/aleh/a21
|
||||
//
|
||||
|
||||
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);
|
||||
#include <a21.hpp>
|
||||
|
||||
using namespace a21;
|
||||
|
||||
//
|
||||
// Here we assume that the pins A and B of a EC-11 rotary encoder are connected to pins 2 and 3 of the Arduino Uno
|
||||
// board and the pin C is connected to the ground.
|
||||
//
|
||||
|
||||
EC11 encoder;
|
||||
|
||||
// Using interrupt-based example by default, comment out or define as 0 to check polling.
|
||||
#define DEMO_INTERRUPTS 1
|
||||
|
||||
#if DEMO_INTERRUPTS
|
||||
|
||||
//
|
||||
// Interrupt-based example. This is recommended, but it means only pins 2 and 3 can be used with Uno.
|
||||
//
|
||||
|
||||
const int encoderPinA = D3;
|
||||
const int encoderPinB = D4;
|
||||
|
||||
void pinDidChange() {
|
||||
encoder.checkPins(digitalRead(encoderPinA), digitalRead(encoderPinB));
|
||||
}
|
||||
|
||||
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");
|
||||
sprocket->activate();
|
||||
void prepare() {
|
||||
attachInterrupt(digitalPinToInterrupt(encoderPinA), pinDidChange, CHANGE);
|
||||
attachInterrupt(digitalPinToInterrupt(encoderPinB), pinDidChange, CHANGE);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
sprocket->loop();
|
||||
yield();
|
||||
#else
|
||||
|
||||
//
|
||||
// Polling allows to use the encoder with any digital input pin.
|
||||
//
|
||||
|
||||
const int encoderPinA = 2;
|
||||
const int encoderPinB = 3;
|
||||
|
||||
void prepare() {
|
||||
}
|
||||
|
||||
#endif // #if DEMO_INTERRUPTS
|
||||
|
||||
void setup() {
|
||||
|
||||
Serial.begin(115200);
|
||||
Serial.println("EC11 Test");
|
||||
|
||||
// We can use internal pull-up with the encoder pins, assuming pin C is simply grounded.
|
||||
pinMode(encoderPinA, INPUT_PULLUP);
|
||||
pinMode(encoderPinB, INPUT_PULLUP);
|
||||
|
||||
prepare();
|
||||
}
|
||||
|
||||
static int value = 0;
|
||||
|
||||
void loop() {
|
||||
|
||||
EC11Event e;
|
||||
if (encoder.read(&e)) {
|
||||
|
||||
// OK, got an event waiting to be handled, its count field is number of steps since the last check.
|
||||
|
||||
if (e.type == EC11Event::StepCW) {
|
||||
// Clock-wise.
|
||||
value += e.count;
|
||||
} else {
|
||||
// Counter clock-wise.
|
||||
value -= e.count;
|
||||
}
|
||||
|
||||
Serial.println(value);
|
||||
}
|
||||
|
||||
#if DEMO_INTERRUPTS
|
||||
|
||||
// Wait quite some time to demonstrate that we can check for events fairly infrequently and still not miss them.
|
||||
delay(200);
|
||||
|
||||
#else
|
||||
|
||||
// With polling-style pin checking we can still read infrequently, but we need to poll the pins often enough.
|
||||
for (int i = 0; i < 200; i++) {
|
||||
encoder.checkPins(digitalRead(encoderPinA), digitalRead(encoderPinB));
|
||||
delay(1);
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user