Skip to main content
define 'reg' as the seed, set it as `static` for persistence
Source Link
Dave X
  • 2.4k
  • 16
  • 30

I don't know that you need all that - just an Arduino and a piezo speaker and a pot if you want to play with the volume.

byte speakerPin = 1;

void generateNoise() {
   static unsigned long int newr;reg = 0x12345678; //seed
  unsigned long int newr;
  unsigned char lobit;
    unsigned char b31, b29, b25, b24;
    b31 = (reg & (1L << 31)) >> 31;
    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 (50);  // Changing this value changes the frequency.
}

I don't know that you need all that - just an Arduino and a piezo speaker and a pot if you want to play with the volume.

void generateNoise() {
    unsigned long int newr;
    unsigned char lobit;
    unsigned char b31, b29, b25, b24;
    b31 = (reg & (1L << 31)) >> 31;
    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 (50);  // Changing this value changes the frequency.
}

I don't know that you need all that - just an Arduino and a piezo speaker and a pot if you want to play with the volume.

byte speakerPin = 1;

void generateNoise() {
  static unsigned long int reg = 0x12345678; //seed
  unsigned long int newr;
  unsigned char lobit;
  unsigned char b31, b29, b25, b24;
  b31 = (reg & (1L << 31)) >> 31;
  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 (50);  // Changing this value changes the frequency.
}

I don't know that you need all that - just an Arduino and a piezo speaker and a pot if you want to play with the volume.

     void generateNoise() {
    unsigned long int newr;
    unsigned char lobit;
    unsigned char b31, b29, b25, b24;
    b31 = (reg & (1L << 31)) >> 31;
    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 (50);}  // Changing this value changes the frequency.
}

I don't know that you need all that - just an Arduino and a piezo speaker and a pot if you want to play with the volume.

     void generateNoise(){
   unsigned long int newr;
   unsigned char lobit;
   unsigned char b31, b29, b25, b24;
   b31 = (reg & (1L << 31)) >> 31;
   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 (50);} // Changing this value changes the frequency.

I don't know that you need all that - just an Arduino and a piezo speaker and a pot if you want to play with the volume.

void generateNoise() {
    unsigned long int newr;
    unsigned char lobit;
    unsigned char b31, b29, b25, b24;
    b31 = (reg & (1L << 31)) >> 31;
    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 (50);  // Changing this value changes the frequency.
}
Source Link
Mike
  • 326
  • 2
  • 3

I don't know that you need all that - just an Arduino and a piezo speaker and a pot if you want to play with the volume.

     void generateNoise(){
   unsigned long int newr;
   unsigned char lobit;
   unsigned char b31, b29, b25, b24;
   b31 = (reg & (1L << 31)) >> 31;
   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 (50);} // Changing this value changes the frequency.