This program steps through 16 outputs.
Ther are still some functions to be developed
- reset (goto step 1)
- reverse
- disable (stop a current step)
- dynamic gatelength according to clock speed
- step selection by control voltage (no clock)
- and a litte bit of code optimizing
TriggerSequencer.cpp
///
// 16 Step Trigger Sequenzer
// Rainer Burkhardt
// Juli 2018
///////////////////////////////
#include "Arduino.h"
#include "Stepper.cpp"
const float maxOutputValue = 255.0;
Stepper stepper = Stepper();
void setup() {}
void loop() { stepper.TuWas(); }
Stepper.cpp
///////////////////////////////
// Rainer Burkhardt
// Juli 2018
// Schritt für Sequenzer
///////////////////////////////
#include "Arduino.h"
#include "FlankenDetektor.h"
class Stepper {
public:
Stepper() { InitPorts(); }
void TuWas() {
NextStep();
ResetTriggers();
};
private:
float triggerLength = 10;
float letzteZeitTriggerOut = 0.0;
int aktuellerSchritt = 1;
int portCVIn = 1; // analog
int portsStep[16] = {22, 24, 26, 28, 30, 32, 34, 36,
38, 40, 42, 44, 46, 48, 50, 52};
int portClock = 47;
int portDisable = 51;
int portReverse = 53;
int portReset = 49;
FlankenDetektor flanke;
void InitPorts() {
pinMode(portClock, INPUT);
flanke = FlankenDetektor(portClock);
pinMode(portDisable, INPUT);
pinMode(portReverse, INPUT);
pinMode(portReset, INPUT);
for (int i = 0; i < 16; i++) {
pinMode(portsStep[i], OUTPUT);
}
}
void NextStep() {
bool flankeHoch = flanke.GetAufsteigendeFlanke();
if (flankeHoch) {
// nächsten Step auslösen
aktuellerSchritt++;
if (aktuellerSchritt > 16) {
aktuellerSchritt = 1;
}
Trigger(aktuellerSchritt);
}
}
void Trigger(int port) {
digitalWrite(portsStep[port - 1], HIGH);
letzteZeitTriggerOut = millis();
Serial.println(port);
}
void ResetTriggers() {
unsigned long ms = millis();
if (ms > letzteZeitTriggerOut + triggerLength) {
for (int i = 0; i < 16; i++) {
digitalWrite(portsStep[i], LOW);
}
}
}
};
FlankenDetektor.h
#include "Arduino.h"
#ifndef FLANKEN_DETEKTOR_H
#define FLANKEN_DETEKTOR_H
class FlankenDetektor {
private :
int gateStatus;
int port;
public: FlankenDetektor();
public: FlankenDetektor(int portNumber);
public: bool GetAufsteigendeFlanke();
};
#endif
FlankenDetektor.cpp
#include "Arduino.h"
#include "FlankenDetektor.h"
FlankenDetektor::FlankenDetektor() {};
FlankenDetektor::FlankenDetektor(int portNumber) {
port = portNumber;
};
bool FlankenDetektor::GetAufsteigendeFlanke() {
bool r = digitalRead(port);
if (r) {
if (!gateStatus) {
r = true;
gateStatus = true;
} else {
r = false;
}
} else {
gateStatus = false;
r = false;
}
return r;
};