NoisePad is an Arduino embroidered white noise generator. The soft circuit is composed by a LilyPad Arduino microcontroller, two 5ΚΩ potentiometers, a PWM white LED and a jack output.

The white noise is generated by creating pseudorandom numbers using bit shift.

A new addition to the Lilytronica sonic performance.

This is the source code:

/* White noise generator
March 2013

Based on:
http://fritzing.org/media/fritzing-repo/projects/s/sleepduino/code/sleepduino.pde
*/

int speakerPin = 2; // speaker connected to digital pin 2
int led = 9; // LED connected to digital pin 9

const int pot1 = A2; // pot 1 connected to analog pin A2
const int pot2 = A3; // pot 2 connected to analog pin A3

int pot1value = 0; // value from pot1
int pot2value = 0; // value from pot2

int output1value = 0; // mapped value from pot1 -> control 1
int output2value = 0; // mapped value from pot2 -> control 2

int ledPWM = 0;

unsigned long int reg; // bit register

void setup() {
Serial.begin(57600); //begin serial communication
pinMode(speakerPin, OUTPUT); // initialize speakerPin1 as an output
pinMode(led, OUTPUT); // initialize speakerPin2 as an output
reg = 0x55aa55aaL; //The seed for the bitstream. It can be anything except 0.

}

void loop() {

pot1value = analogRead(pot1); // read pot1 value, map it to the range of the loop and print it
output1value = map(pot1value, 0, 1023, 1, 500);
Serial.print("pot1value = ");
Serial.print(pot1value);
Serial.print("\t control1 = ");
Serial.print(output1value);

pot2value = analogRead(pot2); // read pot2 value, map it to the range of the delay and print it
output2value = map(pot2value, 0, 1023, 0, 200);
Serial.print("\t pot2value = ");
Serial.print(pot2value);
Serial.print("\t control2 = ");
Serial.println(output2value);

for (int i = 0; i < output1value; i++) { // control 1
generateNoise();
ledPWM = map(pot2value, 0, 1023, 0, 255);
analogWrite (led, ledPWM);
}
delay (output2value); // control 2

}

void generateNoise() { // the noise function
unsigned long int newr;
unsigned char lobit;
unsigned char b31, b29, b25, b24;
b31 = (reg & (1L << 31)) >> 31; // use bit shift to generate pseudorandom numbers
b29 = (reg & (1L << 29)) >> 29;
b25 = (reg & (1L << 25)) >> 25;
b24 = (reg & (1L << 24)) >> 24;
lobit = b31 ^ b29 ^ b25 ^ b24;
newr = (reg << 1) | lobit;
reg = newr;
digitalWrite (speakerPin, reg & 1);

delayMicroseconds (20); // Changing this value changes the frequency.
}

Creative Commons License