From b92ed1a431c33a4fb0d216aaf8181a07cc28da3e Mon Sep 17 00:00:00 2001 From: drake Date: Wed, 30 Oct 2024 22:07:05 -0500 Subject: [PATCH] update for dmx --- .gitmodules | 3 +++ platformio.ini | 1 + src/main.cpp | 14 +++----------- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/.gitmodules b/.gitmodules index b9c49b4..322699b 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,3 +4,6 @@ [submodule "lib/DMXSerial"] path = lib/DMXSerial url = https://github.com/mathertel/DMXSerial +[submodule "lib/PWM"] + path = lib/PWM + url = https://github.com/terryjmyers/PWM diff --git a/platformio.ini b/platformio.ini index f015c4a..6c37389 100644 --- a/platformio.ini +++ b/platformio.ini @@ -13,3 +13,4 @@ platform = atmelavr board = uno framework = arduino monitor_speed = 115200 +; lib_deps = mathertel/DMXSerial@^1.5.3 diff --git a/src/main.cpp b/src/main.cpp index 637cbb5..5654bb1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,7 +1,7 @@ #include #include #include -#include +#include <../lib/PWM/PWM.h> // Motor Driver: IBT-2 (BTS7960) #define LPWM_PIN 9 // LPWM for CCW motion (postive) @@ -30,7 +30,7 @@ #define SAMPLE_RATE 10000 // min time (us) between velocity calculations #define LOOP_RATE 10 // min time (ms) between control adjustments. ** Must be >= SAMPLE_RATE (converted to us) ** -#define DMX_CHANNEL 500 // DMX Channel to read +#define DMX_CHANNEL 2 // DMX Channel to read // wall state variables: long encoderPosition = 0; // raw count from encoder @@ -111,20 +111,12 @@ void setup() { // initialize loop timers prevSample = millis(); prevControl = millis(); - // lastToggle = millis() - 2000; } void loop() { - // if (millis() - lastToggle > 7000) { - // if (targetPosition == 0) { - // targetPosition = 0.5; - // } else { - // targetPosition = 0; - // } - // lastToggle = millis(); - // } if (DMXSerial.noDataSince() < 5000) { + targetPosition = (float)(DMXSerial.read(DMX_CHANNEL) - 101) / 100.0f; // 0 is disabled. position values are 1-201, 101 is center, <101 is CW, >101 is CCW. 1 & 201 are 360 degrees digitalWrite(R_EN_PIN, HIGH); digitalWrite(L_EN_PIN, HIGH);