SGMKtiny
SGMK tiny
easy to use on breadboards with onboard connected ISP port. see general info about Hands On AVR
Pin Layout
Mask
Code Examples
programming the attiny85 with the arduino IDE
Random noise generator
first set the clock divider to 8MHz
clock divided by 8 (1Mhz, as delivered) -U lfuse:w:0x62:m -U hfuse:w:0xdf:m -U efuse:w:0xff:m
clock not divided (8Mhz) avrdude -b 19200 -c usbtiny -p t85 -U lfuse:w:0xe2:m -U hfuse:w:0xdf:m -U efuse:w:0xff:m
/* Pseudo-Random Bit Sequence Generator 2009-11-25 */
/* Copyright (c) 2009 John Honniball, Dorkbot Bristol */
/*
* For a discussion of PRBS generators, see The Art Of Electronics, by
* Horowitz and Hill, Second Edition, pages 655 to 660. For more info
* on Linear Feedback Shift Registers, see Wikipedia:
* http://en.wikipedia.org/wiki/Linear_feedback_shift_register
* For the actual shift register taps, refer to this article on noise
* generation for synthesisers:
* http://www.electricdruid.net/index.php?page=techniques.practicalLFSRs
*/
// Choose the same pin as the "Melody" example sketch
int speakerPin = 0;
int potiPin = 1;
unsigned int analogValue;
int samplingDelay;
unsigned long int reg;
void setup ()
{
// Serial setup for debugging only; slows down the program far too much
// for audible white noise
//Serial.begin (9600);
// Connect a piezo sounder between Ground and this pin
pinMode (speakerPin, OUTPUT);
// Arbitrary inital value; must not be zero
reg = 0x551155aaL;
}
void loop ()
{
unsigned long int newr;
unsigned char lobit;
unsigned char b31, b29, b25, b24;
// Extract four chosen bits from the 32-bit register
b31 = (reg & (1L << 31)) >> 31;
b29 = (reg & (1L << 29)) >> 29;
b25 = (reg & (1L << 25)) >> 25;
b24 = (reg & (1L << 24)) >> 24;
// EXOR the four bits together
lobit = b31 ^ b29 ^ b25 ^ b24;
// Shift and incorporate new bit at bit position 0
newr = (reg << 1) | lobit;
// Replace register with new value
reg = newr;
// Drive speaker pin from bit 0 of 'reg'
digitalWrite (speakerPin, reg & 1);
// Display 'reg' in the serial console for debugging only
// Serial.println (reg, HEX);
samplingDelay = 1 + (2*(analogRead(potiPin)>>0));
// Delay corresponds to 20kHz, but the actual frequency of updates
// will be lower, due to computation time and loop overhead
delayMicroseconds (samplingDelay);
// If the above delay is increased to a few tens of milliseconds,
// and the piezo sounder is replaced by an LED and a suitable series
// resistor, a randomly flashing light will result. Several LEDs
// could be driven from various bits of the shift register.
}
from [http://tziteras.blogspot.com/2009/11/green-noise-experiment.html John Honnibal]