## Ardcore sketch: NoiseCore random stepped + burst

Discussion and Support for our Atmospheric Modification Devices.

Moderators: Kent, loss1234

studiokpg
Resplendent in Divergence
Posts: 337
Joined: Sat Nov 13, 2010 11:41 am
Location: NoVa

### Ardcore sketch: NoiseCore random stepped + burst

Hey, here's a new sketch I made, inspired by Grant Richter's Noise Ring. It uses an 8-bit rotating output "ring" with 1s and 0s being modified by using A2 and A3 as comparators on a random. A2 is similar to the Change knob and A3 is similar to the Chance knob. A0 is tempo, and A1 controls how much the randomness contributes to tempo (similar to ext. rate, except there is no ext. rate input .) When A0 is all the way counterclockwise, it follows external clock instead of the internal clock. D0 is a trigger out that goes with the random stepped voltage.
The trigger burst at D1 is based on the random output. A3 doubles as a comparator level on the random; when the random goes below that level, burst is triggered. The number of triggers in the burst depends on how long since the last burst. A1 also doubles as the rate control of the burst triggers.
Here is demo on Soundcloud. The main out is controlling a Z3000, the burst is triggering a brains sequence playing a DPO.
https://soundcloud.com/studiokpg/noisecore-experiment

// ============================================================
//
// Program: ArdCore Random Stepped Voltage Generator
// Inspired by my limited understanding of Grant Richter's fabulous Noise Ring
// in turn inspired by Don Buchla's Source of Uncertainty
// and other vaguely understood randomness.
//
// I/O Usage:
// Knob 1 (A0): Tempo (0 = clocked only)
// Knob 2 (A1): Amount of random to tempo (unless clocked) and rate of burst triggers
// Analog In 1 (A2): Chance input
// Analog In 2 (A3): Change input and comparator level for burst likelyhood
// Digital Out 1: Clock out
// Digital Out 2: Burst triggers out
// Clock In: External clock input
// Analog Out: Random stepped voltage
//
//
// Created: 3 May 2014 by Karl Gruenewald (studiokpg@gmail.com)
// Modified: 27 May 2014 by Karl Gruenewald working on clock input
// Modified: 1 June 2014 by Karl Gruenewald adding burst mode
//

// ================= start of global section ==================

// constants related to the Arduino Nano pin use
const int clkIn = 2; // the digital (clock) input
const int digPin[2] = {3, 4}; // the digital output pins
const int pinOffset = 5; // the first DAC pin (from 5-12)
const int trigTime = 10; // 10 ms trigger time

// variables for interrupt handling of the clock input
volatile int clkState = LOW;

unsigned int ring; //variable for holding the value
unsigned int notring; //for flipping bits
int temp; //variable for rotating bits
unsigned long nextClock = 0;
unsigned long prevClock = 0;
unsigned long nextOffClock = 0;
unsigned long bNext = 0;
unsigned long bNextOff = 0;
float clockAmt = 0;
float modfactor = 0;
int lastRead = 0;
int bTrigs = 0;
int bRate = 0;
boolean burstSet = false;

// ==================== start of setup() ======================

void setup() {
Serial.begin(9600);

// set up the digital (clock) input
pinMode(clkIn, INPUT);

// set up the digital outputs
for (int i=0; i<2; i++) {
pinMode(digPin, OUTPUT);
digitalWrite(digPin, LOW);
}

// set up the 8-bit DAC output pins
for (int i=0; i<8; i++) {
pinMode(pinOffset+i, OUTPUT);
digitalWrite(pinOffset+i, LOW);
}

// set up the interrupt
attachInterrupt(0, isr, RISING);

// generate a new random seed

ring = random(255);

}

// ==================== start of loop() =======================

void loop()
{
if (analogRead(0) <= 1) {
if (clkState == HIGH) {
doRing();
clkState = LOW;
prevClock = millis();
}
}

modfactor = ((ring / 255.0) + 0.5) * ((analogRead(1) + 1.0) / 1700.0);
clockAmt = 1023 - analogRead(0) + 5; //5ms is minimum cycle
nextClock = prevClock + clockAmt - (clockAmt * modfactor * .75);

if (millis() >= nextClock) {
if(analogRead(0) > 1) doRing();
}

bRate = 200 - (analogRead(1) / 6) ; //burst rate

if (burstSet == true && millis() >= bNext) {
digitalWrite(digPin[1], HIGH);
bNext = millis() + bRate;
bNextOff = millis() + 10; //trig width 10ms for bursts
if (bTrigs <= 0) burstSet = false;
bTrigs --;
}

if (millis() >= nextOffClock) digitalWrite(digPin[0], LOW);

if (millis() >= bNextOff) {
digitalWrite(digPin[1], LOW);
}
}

void doRing()
{
dacOutput(ring);
digitalWrite(digPin[0], HIGH);
if (clockAmt <= 20) {
nextOffClock = millis() + (clockAmt / 2); //shorter triggers at very fast clocks
}
else nextOffClock = millis() + trigTime;
notring = ~ring;
temp = notring & 1;
if (random(1023) < analogRead(3)) {
if (random(1523) > analogRead(2)+250) { //make it less likely to have all min or max values
temp = 0;
}
else temp = 1;
}
ring = ring >> 1;
temp = temp << 7;
ring = ring | temp;
prevClock = millis();

if (ring <= (analogRead(3) - 25) / 4 && bTrigs > 0) { //comparator for ring and ar(3)
burstSet = true;
}
else bTrigs ++;
if (bTrigs > 10) bTrigs = 10; //limit number of triggers in burst
Serial.println(bTrigs);
}

// =================== convenience routines ===================

// dacOutput(byte) - deal with the DAC output
// -----------------------------------------
void dacOutput(byte v)
{
PORTB = (PORTB & B11100000) | (v >> 3);
PORTD = (PORTD & B00011111) | ((v & B00000111) << 5);
}

// isr() - quickly handle interrupts from the clock input
// ------------------------------------------------------
void isr()
{
clkState = HIGH;
}

// ===================== end of program =======================

eclectics
Wiggling with Experience
Posts: 368
Joined: Sat Oct 05, 2013 10:32 am
Location: Melbourne
This is playing very nicely with my Turing Machine, thanks-- I'm using the burst to drive the TM clock, and the 2 random sources are cving oscillators, then ring modding the output.

studiokpg
Resplendent in Divergence
Posts: 337
Joined: Sat Nov 13, 2010 11:41 am
Location: NoVa
Glad you like it!

paperwork
Common Wiggler
Posts: 164
Joined: Wed May 01, 2013 8:51 pm
Location: Kentucky
This is great - thanks!

Playing around with it this afternoon:

paperwork
Common Wiggler
Posts: 164
Joined: Wed May 01, 2013 8:51 pm
Location: Kentucky
Just finally picked up an Ardcore expander & this sketch is great with it! It exposes the 8 bits of the value on individual outputs. It's a bit like the behavior of the "pulses" expander for the Turing Machine, particularly when feeding a few bits into a logic module for AND/OR/XOR combinations.

onurkalaycioglu
Veteran Wiggler
Posts: 538
Joined: Fri Jun 07, 2013 5:01 pm
Location: Chicago, IL
great sketch
Żłób modules, pcbs, and kits available at:
http://zlobmodular.com/

My Eurorack compositions for vinyl "Tholins of Kharon" is out 11/23/19
http://zlobmodular.com/music/

Solo modular synth recordings using Buchla, Serge, and Eurorack:
https://onurzlobnicki.bandcamp.com/album/

Eps by my metal band
http://burningchurches.bandcamp.com/releases