arduiNoise(beats);

Bit-music loving Arduino users - I ported (and modded a bit) one of the Noise Toy programs over to the lovely and talented Arduino platform. Just add a couple of momentary switches to pins 8 and 9 and connect stereo audio to 3 and 4 - you're done. Loud Objects' code proved quite fun to tinker/learn with - if you're curious, try experimenting with different tempo values.

Read on to view and download-o the code-uino.

Makershedsmall
noisetoy_kit_crop.jpg
Loud Objects Noise Toy kit

Arduino Crop
Arduino Diecimila

/* Stereo BeatGen v1 - originally written by Loud Objects for the ATTiny85/NOISE TOY projects loudobjects.com - adapted/messed with for Arduino by Collin Cunningham me [at] collinmel.com assumes pins 3 & 4 connected to left & right audio momentary switches between 8 & 9 and GND */

unsigned long NextRandom = 1;
unsigned long Bass_Start = 300, Bass_End = 600;
unsigned char Last_Val_Left = 1, Last_Val_Right = 1;
unsigned long Bass_Left_Period = Bass_Start, Bass_Right_Period = Bass_Start;
unsigned long Bass_Left_Sample = 1, Bass_Right_Sample = 1;
unsigned char Bass_Left_On = 1, Bass_Right_On = 1;
unsigned char Snare_Left_On = 1, Snare_Right_On = 1;
unsigned char Snare_Left_Sample = 1, Snare_Right_Sample = 1;
unsigned long Tempo_Period = 1200, Tempo_Outer = 1, Tempo_Sample = 1;
unsigned char Trax_Left[] = {
1, 2, 3, 0, 3, 2, 0, 1};
unsigned char Trax_Right[] = {
2, 1, 0, 3, 1, 3, 0, 2};
unsigned char Track_Index = -1;
unsigned long New_Rand = randomGen();
unsigned long NextRandom2 = 1;
unsigned long Snare_Length = 500;

void setup()
{
// SET PINS 3 AND 4 AS OUTPUTS
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(2, INPUT);

// SET PULL-UP RESISTORS ON PINS 9 AND 8
pinMode(9, INPUT);
pinMode(8, INPUT);
digitalWrite(9, HIGH);
digitalWrite(8, HIGH);
digitalWrite(5, LOW);

}

void loop(){


NextRandom2 = NextRandom2 + 9;
New_Rand = NextRandom2;

// UPDATE SAMPLES
if (Bass_Left_On)
{
if (!(--Bass_Left_Sample))
{
if ((Bass_Left_Period += 11) > Bass_End)
{
Bass_Left_On = 0;
}
Bass_Left_Sample = Bass_Left_Period;
Last_Val_Left = 1 - Last_Val_Left;
}
}


if (Bass_Right_On)
{
if (!(--Bass_Right_Sample))
{
if ((Bass_Right_Period += 13) > Bass_End)
{
Bass_Right_On = 0;
}
Bass_Right_Sample = Bass_Right_Period;
Last_Val_Right = 1 - Last_Val_Right;
}
}


if (Snare_Left_On)
{
if (!(--Snare_Left_Sample))
{
Snare_Left_Sample = New_Rand / 200;// % 10;
Last_Val_Left = 1 - Last_Val_Left;
}
if (!(--Snare_Length))
{
Snare_Left_On = 0;
}
}


if (Snare_Right_On)
{
if (!(--Snare_Right_Sample))
{
Snare_Right_Sample = New_Rand / 200;// % 10;
Last_Val_Right = 1 - Last_Val_Right;
}
if (!(--Snare_Length))
{
Snare_Right_On = 0;
}
}

// CHECK FOR NEXT BEAT
if (!(--Tempo_Outer))
{
Tempo_Outer = 10;
if (!(--Tempo_Sample))
{
if (++Track_Index == 8)
Track_Index = 0;

Tempo_Sample = Tempo_Period;
Bass_Left_On = (Trax_Left[Track_Index] & 1);
Bass_Right_On = (Trax_Right[Track_Index] & 1);
Snare_Left_On = (Trax_Left[Track_Index] & 2);
Snare_Right_On = (Trax_Right[Track_Index] & 2);
Snare_Length = 5000;
Bass_Left_Period = Bass_Start;
Bass_Left_Sample = 1;
Bass_Right_Period = Bass_Start;
Bass_Right_Sample = 1;
}
}

// OUTPUT
if (Last_Val_Left)
PORTD |= (1 << 3);
else
PORTD &= ~((1 << 3));
if (Last_Val_Right)
PORTD |= (1 << 4);
else
PORTD &= ~((1 << 4));


// BUTTON INPUT CHECKS
//pin 8 for tempo
if ((digitalRead(8)) == LOW)
{
randomSeed(analogRead(0));
Tempo_Period = (random(1627) / 15 * 25); // experiment with diff values for better range
}
//pin 9 for beat
if (digitalRead(9) == LOW)
{
unsigned char i;
for (i = 0; i < 8; i++)
{
Trax_Left[i] = randomGen();
Trax_Right[i] = randomGen();
}
}
}

unsigned long randomGen(void) //pseudo random from original sketch
{
NextRandom = NextRandom * 3865 + 131;
return ((NextRandom >> 16) & 32767);
}



Related:

Posted by Collin Cunningham | Aug 28, 2008 02:30 PM
Arduino, Music | Permalink | Comments (2) | Email This | Bookmark and Share | Digg this!

Recent Entries

Comments

Oldest comments listed first.

Posted by: VanessaC on August 29, 2008 at 12:37 PM

Awesome project, found an Arduino Synth here

Hey, seems like a great project, very straightforward which is nice, its not too complicated to get started with! I found a great project here that's similar, called the Arduino Synth: http://halfmachine.dk/posts/171

They say "We would like to make it possible to make installations which emits sounds and music without the need to have a computer connected. We needed to create a stand alone sound creation device which could be controlled by real time user input." ... "potentiometers are used to control the individual properties of each wave generator. In this way, sound can be controlled manually while playing music."

Thanks for the post, nice work!

Vanessa


Posted by: Collin Cunningham on September 2, 2008 at 7:04 PM

@VanessaC - Nice find! Glad you enjoyed the post.


Leave a comment


Subscribe to MAKE!Subscribe to MAKE Magazine!

Subscribe today, save 42% and get web access to MAKE free. MAKE Digital Edition is available only to subscribers.

$34.95 / 1 year
(4 Quarterly Issues)

Subscribe now

How-to videos for Makers and Crafers!


Void your warranty, violate a user agreement, fry a circuit, blow a fuse, poke an eye out... Welcome to the Make Blog!

Features and more @ MAKE!

Maker shed - cool stuff to make!
Stop by the Maker Shed store and check out THE place for open source hardware, Arduino & Arduino accessories, electronic kits, science kits, smart stuff for kids, back issues of MAKE & CRAFT, box sets, books, robots, kits from Japan and more.

Add MAKE to iGoogle - GoogleGoogle.
Add MAKE to your RSS reader - Real simple.
Add MAKE on Twitter.
Add MAKE on FriendFeed & the MAKE room.


Advertise here with FM.

Why advertise on MAKE?
Read what folks are saying about us!

Click here to advertise on MAKE!

Subscribe to MAKE Magazine!

Makezine authors!


Suggest a Site!

Phillip Torrone
Senior Editor
Tel: 707-827-7311
Twitter / AIM

Gareth Branwyn
Jonah Brucker-Cohen
Collin Cunningham
Marc de Vinck
Kip Kay
Luke Iseman
Patti Schiendelman
Becky Stern
Mike Dixon
Peter Horvath(intern)


Current Podcast

itunesdl.gif The Best of Maker Faire Austin 2008 Check out all the fun and excitement at this year's Maker Faire in Austin, Texas. People from all over the world came to experience this amazing event. Take a look at some of the highlights and make plans to... More...

Get the Make blog sent via email

Enter your email to receive the Make blog each day:



WOW! Thanks to everyone involved with Maker Faire Bay Area and Maker Faire Austin in 2008: attendees, makers, exhibitors, sponsors, volunteers, and crew...it was an AMAZING year! Over 1,000 Makers and 87,000+ attendees total! Be sure to check out the photos @ Flickr, and our Maker Faire posts for all the action! Check back for dates for 2009 soon!

Make Categories

www.flickr.com
photos in MAKE More photos in MAKE Flickr Pool
www.flickr.com
photos in Craft More photos in Craft Flickr Pool

Advertise here.
Why advertise on MAKE?
Read what folks are saying about us!

Click here to advertise on MAKE!
Subscribe to MAKE Magazine!

Recent Posts from the Craft: Blog

Recent Posts from the Hackszine Blog