I`m working in same direction with arduino. And I have euclide routine done in software. My problem is to add midi and buttons and rotary encoder with it in one thing for quick twiking a pattern. And of couse I want my box to follow midi clock.
Maybe someone want join to project? and help me with this?
this code calculates and store pattern in memory, and show it on LCD
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int remainder[16];
int count[16];
int level;
int steps;
int pulses;
int pauses;
int patit=0;
char pattern[16];
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
Serial.begin(9600);
}
void loop() {
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
compute_bitmap(7,3); // Here we add how many Steps/Pulses we need
lcd.setCursor(0, 0);
lcd.print(steps);lcd.print("/");lcd.print(pulses);
pauses = steps - pulses;
Serial.println(); //debug
//if (pauses > pulses) {
// for (int l = steps; l >= 0; l--) { //for pauses > pulses
// lcd.setCursor(l, 0);
// lcd.print(pattern[l]);
// }
//} else {
for (int l = 0; l < steps; l++) { //for pauses < pulses
// lcd.setCursor(l, 0);
// lcd.print(pattern[l]);
Serial.print(pattern[l]);
}
//}
delay (1000);
}
void compute_bitmap (int num_slots,int num_pulses) {
if (num_pulses > num_slots) {num_pulses = num_slots;} // Sane input
int divisor = num_slots - num_pulses;
steps = num_slots; pulses = num_pulses;
remainder[0] = num_pulses;
level = 0;
do {
count[level] = divisor / remainder[level];
remainder[level+1] = divisor % remainder[level];
divisor = remainder[level];
level = level +1; }
while (remainder[level] > 1);
count[level] = divisor;
build_string (level);
}
void build_string (int level) {
if (level == -1) {
lcd.print('0');
pattern[patit]='0'; //0 into array pattern
patit=patit+1; //plus 1
}
else if (level == -2) {
lcd.print('1');
pattern[patit]='1'; //1 into array pattern
patit=patit+1; //plus 1
}
else {
for (int i = 0; i < count[level]; i++)
build_string(level-1);
if (remainder[level] !=0)
build_string(level-2);
}//end else
}//end build_string