Skip to content

Instantly share code, notes, and snippets.

@rjungemann
Created May 16, 2012 07:58
Show Gist options
  • Save rjungemann/2708498 to your computer and use it in GitHub Desktop.
Save rjungemann/2708498 to your computer and use it in GitHub Desktop.
Euclidian sequencer proof-of-concept for Ardcore
/*
A simple two-channel euclidian sequencer (work-in-progress).
Currently supports one channel. Caveat: there may be bugs. I just got my Ardcore
and I started developing this before it arrived.
Given an input like (A), it should send out something like (B) in a loop:
(A) * * * * * * * *
(B) * * *
TODO:
* Make length settable from first knob
* Make offset for the second channel settable from the second knob
* Make length for first channel settable from third knob
* Make length for second channel settable from fourth knob
*/
const int clkIn = 2;
const int digPin = 3;
volatile int clkState = LOW;
volatile int digState = LOW;
int n = 0; // current input ping count
int count = 3; // number of pings to output per measure
int offset = 0; // number of pings at start of measure to wait
int length = 8; // length of measure in pings
void setup() {
pinMode(clkIn, INPUT);
pinMode(digPin, OUTPUT);
digitalWrite(digPin, LOW);
attachInterrupt(0, isr, RISING);
}
void loop() {
if(clkState == HIGH) {
clkState = LOW;
digState = hit(n, count, offset, length) ? HIGH : LOW;
digitalWrite(digPin, digState);
}
n++;
}
void isr() {
clkState = HIGH;
}
// calculate whether to send an output ping or not
boolean hit(int n, int count, int offset, int length) {
return ( (n + offset) * count ) % length < count;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment