| Author |
Message |
Franky

Joined: Dec 09, 2007 Posts: 30 Location: Grenoble - France
|
Posted: Sat May 03, 2008 10:29 am Post subject:
Arduino-based Sequencer Subject description: A polyvalent sequencer from an Arduino board |
 |
|
Hi guys, I've bought an Arduino board (not exactly the real Arduino, a clone, but it's doing exactly the same stuff), and I had some toughts about a little (but powerfull) sequencer to do with.
Here's the thing:
8 steps
3 resets modes (4th ,6th or 8th step)
3 running modes: forward, reverse, pendullum (mirror mode)
Controls:
Frequency CV (0-5V range)
Gate Length CV (0-5V range)
Gate out - 5V
8 step-gates out (no CV, no pots)
Here's the code:
| Code: |
**************************************
*
* ARDUINO SEQUENCER
* Source Code by: Franky
* Version: 0.1 beta
* License: Copyleft (free)
*
**************************************
int i;
int freqPin = 0; // Analog freq control
int pwPin = 1; // Analog PW control (gate length)
int modePin1 = 8;
int modePin2 = 9;
int gatePin = 10;
int freq; // Frequency value
int gl; // Gate Lenght value
int uns; // Time Until NeXTStep
int resetPin1 = 11;
int resetPin2 = 12;
void blink(char nbre) {
char i;
for (i=0;i<nbre;i++) {
digitalWrite(ledPin, HIGH);
delay(500);
digitalWrite(ledPin, LOW);
delay(500);
}
}
void setup() {
pinMode(0, OUTPUT);
pinMode(1, OUTPUT);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(modePin1, INPUT);
pinMode(modePin2, INPUT);
pinMode(resetPin1, INPUT);
pinMode(restePin2, INPUT);
pinMode(gatePin, OUTPUT);
blink(3);
}
int moderead() {
int mode1;
int mode2;
mode1 = digitalRead(modePin1);
mode2 = digitalRead(modePin2);
if (mode1 == LOW && mode2 == HIGH) return 1;
if (mode2 == LOW && mode2 == LOW) return 2;
if (mode2 == HIGH && mode2 == LOW) return 3;
else return 0; /* Should never happen */
}
int resetpoint() {
int r1 = digitalRead(resetPin1);
int r2 = digitalRead(resetPin2);
if (r1 == LOW && r2 == HIGH) return 4;
if (r2 == LOW && r2 == LOW) return 6;
if (r2 == HIGH && r2 == LOW) return 8;
else return 8; /* Should never happen */
}
void loop() {
switch (moderead()) {
case 0:
break; /* Should never happen */
case 1: // Forward mode
for (i=0; i<resetpoint(); i++) {
freq = analogRead(freqPin);
gl = (analogRead(pwPin)*freq)/1024;
uns = freq-gl;
digitalWrite(i, HIGH);
digitalWrite(gatePin, HIGH);
delay(gl);
digitalWrite(i, LOW);
digitalWrite(gatePin, LOW);
delay(uns);
}
break;
case 2: // Mirror mode
for (i=0; i<resetpoint>0; i--) {
freq = analogRead(freqPin);
gl = (analogRead(pwPin)*freq)/1024;
uns = freq-gl;
digitalWrite(i, HIGH);
digitalWrite(gatePin, HIGH);
delay(gl);
digitalWrite(i, LOW);
digitalWrite(gatePin, LOW);
delay(uns);
}
break;
case 3: // Reverse mode
for (i=(resetpoint()-1); i>=0; i--) {
freq = analogRead(freqPin);
gl = (analogRead(pwPin)*freq)/1024;
uns = freq-gl;
digitalWrite(i, HIGH);
digitalWrite(gatePin, HIGH);
delay(gl);
digitalWrite(i, LOW);
digitalWrite(gatePin, LOW);
delay(uns);
}
break;
}
}
|
There are some pins available on the board, so it can be upgraded.
The code is free, you can do whatever you want with it.. _________________ Keep on Sliding |
|
|
Back to top
|
|
 |
Joel
Joined: Sep 12, 2006 Posts: 96 Location: London, UK
|
Posted: Sat May 03, 2008 11:08 am Post subject:
|
 |
|
Looks great! I've got an Arduino somewhere, will have to dig it out and give this a go when I get a chance....
It uses some different methods, but have you seen the Arduino Punk Console?
p.s. what does polyvalent mean, in relation to a sequencer?
Thanks for posting, Joel |
|
|
Back to top
|
|
 |
Franky

Joined: Dec 09, 2007 Posts: 30 Location: Grenoble - France
|
Posted: Sat May 03, 2008 1:01 pm Post subject:
|
 |
|
By polyvalent I mean it can run through several modes, where a classic "analog" sequencer can only go through one: forward. Here are 2 more running modes, allowing different sequences..
Wow, the punk console sounds great! Sounds like an old NES console lol..
Didn't try the audio possibilities of the Arduino so far, but i'm gonna give it a go.. _________________ Keep on Sliding |
|
|
Back to top
|
|
 |
okvern
Joined: Feb 05, 2008 Posts: 65 Location: Seattle, Washington
Audio files: 5
|
Posted: Wed May 07, 2008 12:54 am Post subject:
|
 |
|
Fellow Builders,
The Arduino is cool, definitely a platform to watch--take a look at the Arduino-related stuff at:
http://little-scale.blogspot.com/2008/02/simple-polyphonic-synth-with-just.html
I've gotten distracted by PICs lately because of a couple of projects, but I'll be going back to the Arduino soon.
re: the punk console
It's great that they used Visio for their panel layouts--I was Visio (pre-Microsoft) employee #11, title "Shapemaster," and they probably used shapes I wrote. I use it for all my panel layouts, and for some circuit board layouts.
Thanks,
Ole |
|
|
Back to top
|
|
 |
beavis
Joined: Aug 23, 2007 Posts: 12 Location: US
|
Posted: Wed May 07, 2008 8:27 am Post subject:
|
 |
|
| okvern wrote: | Fellow Builders,
re: the punk console
It's great that they used Visio for their panel layouts--I was Visio (pre-Microsoft) employee #11, title "Shapemaster," and they probably used shapes I wrote. I use it for all my panel layouts, and for some circuit board layouts.
Thanks,
Ole |
I'm the guy who used visio for all that stuff
I've been around long enough to have used visio pre-MSFT, so its great to meet you!
I do schematics, enclosure layouts, drilling templates, build guides and even PCB layouts all in Visio. It simple rocks. _________________ www.beavisaudio.com |
|
|
Back to top
|
|
 |
Kassen
Janitor


Joined: Jul 06, 2004 Posts: 6722 Location: The Hague, NL
G2 patch files: 3
|
Posted: Wed May 07, 2008 4:09 pm Post subject:
|
 |
|
I've got a borrowed Arduino here now. I've only had it for a few days and didn't get round to it beyond a quick look at the syntax. Looks very accessible indeed, thanks for the nice links. _________________ Modern technology offers an endless field day to any deviant strains in our personalities. --J.G.Ballard |
|
|
Back to top
|
|
 |
okvern
Joined: Feb 05, 2008 Posts: 65 Location: Seattle, Washington
Audio files: 5
|
Posted: Wed May 07, 2008 7:41 pm Post subject:
|
 |
|
Hi Franky,
I think gremlins got at your code a bit in the posting process--which is pretty common when posting code on forums. This happens to me every time, and I *run* a forum! First, we're missing a define--add:
int ledPin = 13; // LED connected to digital pin 13
There's a typo in your setup function--"restePin2" should be "resetPin2".
Next, I think that this:
for (i=0; i<resetpoint>0; i--) {
Should probably be:
for (i=0; i < resetpoint() > 0; i--) {
(Even though it looks like you've surrounded your code with a <code> or <pre> element, it looks like the forum decided that "resetpoint" belonged in a tag.)
Once I made those changes, it seems to compile and download fine--now I have to set up a breadboard to attach the controls. I think I can deduce what everything is supposed to be, but if you have a chance to post a note about pots/switches we need to attach, that would be great.
Thanks for sharing this code!
Ole |
|
|
Back to top
|
|
 |
Blue Hell
Site Admin

Joined: Apr 03, 2004 Posts: 11968 Location: Netherlands, Enschede
Audio files: 28
G2 patch files: 295
|
Posted: Thu May 08, 2008 1:57 am Post subject:
|
 |
|
| okvern wrote: | | (Even though it looks like you've surrounded your code with a <code> or <pre> element, it looks like the forum decided that "resetpoint" belonged in a tag.) |
Note to code posters : using the "Disable HTML in this post" option helps. _________________ Jan |
|
|
Back to top
|
|
 |
Kassen
Janitor


Joined: Jul 06, 2004 Posts: 6722 Location: The Hague, NL
G2 patch files: 3
|
Posted: Thu May 08, 2008 2:54 am Post subject:
|
 |
|
Also; using the code tag will preserve indentation and get you a monospaced font. If you don't use it all spaces and tabs at the start of lines will be removed.
Typically it's wise to disable smileys as well. _________________ Modern technology offers an endless field day to any deviant strains in our personalities. --J.G.Ballard |
|
|
Back to top
|
|
 |
Franky

Joined: Dec 09, 2007 Posts: 30 Location: Grenoble - France
|
Posted: Thu May 08, 2008 3:40 pm Post subject:
|
 |
|
Damn it, you're right, and it seems that a big part of the code is missing: look at the Mirror mode, it only goes one way..
I'm not using the #define system to declare my pins, it didn't work at first, so I came up to declare this way.. Anyway it's the same..
About ledPin, i'm just using it to blink 3 times once the sketch is done uploading, you're not forced to use it.. It saves a pin moreover..
Thanks for the typo mistake, I didn't compile it so I could'nt know..
New try:
| Code: |
/*
**************************************
*
* ARDUINO SEQUENCER
* Source Code by: Franky
* Version: 0.2b
* License: Copyleft (free)
*
**************************************
*/
int i;
int freqPin = 0; // Analog freq control (analog in)
int pwPin = 1; // Analog PW control (gate length) (analog in)
int modePin1 = 8; // Reading from mode switch (digital in)
int modePin2 = 9; // idem (digital in)
int resetPin1 = 10;// Reading reset switch (digital in)
int resetPin2 = 11;// idem (digital in)
int gatePin = 12; // Gate out pin (digital out)
int ledPin = 13; // Used for blink() function (digital out)
int freq; // Frequency value
int gl; // Gate Lenght value
int uns; // Time Until NeXTStep
void blink(char nbr) {
for (i=0;i<nbr;i++) {
delay(500);
digitalWrite(ledPin, HIGH);
delay(500);
digitalWrite(ledPin, LOW);
}
}
void setup() {
pinMode(0, OUTPUT); // Output pins, digital out
pinMode(1, OUTPUT);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(modePin1, INPUT);
pinMode(modePin2, INPUT);
pinMode(resetPin1, INPUT);
pinMode(resetPin2, INPUT);
pinMode(gatePin, OUTPUT);
blink(3);
}
int moderead() {
int mode1;
int mode2;
mode1 = digitalRead(modePin1);
mode2 = digitalRead(modePin2);
if (mode1 == LOW && mode2 == HIGH) return 1;
if (mode2 == LOW && mode2 == LOW) return 2;
if (mode2 == HIGH && mode2 == LOW) return 3;
else return 0; /* Should never happen */
}
int resetpoint() {
int r1 = digitalRead(resetPin1);
int r2 = digitalRead(resetPin2);
if (r1 == LOW && r2 == HIGH) return 4;
if (r2 == LOW && r2 == LOW) return 6;
if (r2 == HIGH && r2 == LOW) return 8;
else return 8; /* Should never happen */
}
void loop() {
switch (moderead()) {
case 0:
break; /* Should never happen */
case 1: // Forward mode
for (i=0; i<resetpoint(); i++) {
freq = analogRead(freqPin);
gl = (analogRead(pwPin)*freq)/1024;
uns = freq-gl;
digitalWrite(i, HIGH);
digitalWrite(gatePin, HIGH);
delay(gl);
digitalWrite(i, LOW);
digitalWrite(gatePin, LOW);
delay(uns);
}
break;
case 2: // Mirror mode
for (i=0; i<resetpoint(); i++) {
freq = analogRead(freqPin);
gl = (analogRead(pwPin)*freq)/1024;
uns = freq-gl;
digitalWrite(i, HIGH);
digitalWrite(gatePin, HIGH);
delay(gl);
digitalWrite(i, LOW);
digitalWrite(gatePin, LOW);
delay(uns);
}
// Steps 1 & 8 are triggered in forward loop
// reverse loop does not repeat it at the ends
for (i=(resetpoint()-2); i>0; i--) {
freq = analogRead(freqPin);
gl = (analogRead(pwPin)*freq)/1024;
uns = freq-gl;
digitalWrite(i, HIGH);
digitalWrite(gatePin, HIGH);
delay(gl);
digitalWrite(i, LOW);
digitalWrite(gatePin, LOW);
delay(uns);
}
break;
case 3: // Reverse mode
for (i=(resetpoint()-1); i>=0; i--) {
freq = analogRead(freqPin);
gl = (analogRead(pwPin)*freq)/1024;
uns = freq-gl;
digitalWrite(i, HIGH);
digitalWrite(gatePin, HIGH);
delay(gl);
digitalWrite(i, LOW);
digitalWrite(gatePin, LOW);
delay(uns);
}
break;
}
}
|
About the hardware:
For the mode button, the best is a 3 position toggle switch, on-off-on, with the center pin connected to VCC, and the others to modePin1 & modePin2 with their pullup resistors. It's the same for the reset button, and it will reset on steps 4, 6 or 8.
Each output should be connected to a pot wired as a voltage divider, with a diode (1N4148 should do the job) in series with the cursor, then connect all the cathodes together so the current can't flow back to the Arduino. And you've got your sequencer..
I can post a schematic if you want, but it's a very basic workout..
Edit: I have some thoughts about a sequencer using only switches and a few pots, like the punk console, with rotary encoders to set the pitch and the same kind of sequence modes i've got here.. _________________ Keep on Sliding |
|
|
Back to top
|
|
 |
|