Hello again. Today I'd like to show you the Auduino. That's right, the Auduino is a Lo-fi Granular Synth that works on arduino. It uses some analog pins and a digital pin. I had loads of fun making and playing with it so I'd love to show you how to make it.
Sketch created by Peter Knight, Tinker.it http://tinker.it.
For more information please visit the website.

I hope you are already familiarized with the arduino environment, if not get an arduino and check for more information at arduino.cc

Step 1: Materials

For making this synth you will need:
  • X5 5K Potentiometer
  • A breadboard.
  • An 8 Ohm speaker or a jack.

This you'll probably have laying around and will be needed:
  • Various jumpers
  • X1 Arduino (I am using Arduino Uno R2) 

  • X5 Knob (For the Pots) 
Hi ! pots going in serial or parallel ? only works 1 at time.
<p>Apologies I'm a noob whatsingnal are you sending to the ardunio from you compute?</p><p>Cheers</p>
<p>I could use a potentiometer of 10k instead of 5k (it's just that I have here)?</p>
<p>From the man himself:</p><p><a href="https://groups.google.com/forum/#!topic/auduino/DaDDdf6O1iQ" rel="nofollow">https://groups.google.com/forum/#!topic/auduino/Da...</a></p><p>Anything between 1K and 50K. I've built two of these and the only difference the resistance makes is the range of control. 5K to 10K is a pretty good level of control. Any higher and you'll find yourself making tiny little movements and skipping over large chunks of the scale. I may try one of those multi-turn pots in the future if I'm ever bored enough. </p>
<p>Thanks, man! @matsugawa ((:</p>
For some reason I can only get one knob to do anythin of the 4, anyone else with this issue?
<p>Same issue. I can only get the frequency swipe but none of the others work or seem to do anything. I've tried every wire combination but only one controls. Did you figure this out?</p>
<p>I have Arduino Leonardo and Arduino IDE 1.6.7 and i have following error:</p><p>'TCCR2A' was not declared in this scope (line 134)</p>
<p>The Leonardo has no Timer2 so most sketches you find on the internet including this one that use this Timer won't work.</p>
<p>Huge fan of this project. Question though, if I wanted to upgrade the speaker, not really aiming for sound quality as much as volume, how would I go about doing so? As you can tell I'm quite new. Really appreciate any tips though. </p>
<p>Do you think this would work with 100k ohm pots?</p>
<p>my parts are coming soon!??</p>
<p>I made one of these. Then I added MIDI support. Very fun</p><p><iframe allowfullscreen="" frameborder="0" height="281" src="//www.youtube.com/embed/ZcXmspfqsyw" width="500"></iframe></p>
<p>I love this project. It's one of the first things I built when I got my Arduino. I recently added basic vactrol based CV inputs so I could use the granular synth with my Lunetta CMOS based noise machine. </p><p><a href="https://www.instructables.com/id/Adding-CV-inputs-to-the-Auduino-granular-synth/" rel="nofollow">https://www.instructables.com/id/Adding-CV-inputs-t...</a></p><p>I entered my CV version of the Auduino in the Remix contest. I gave you all the credit for the original project of course.</p><p>Thanks- this really has become one of my favorite instruments. When my friend the synth snob heard it for the first time he said 'wow, it's about time you built a real analog synth'. When I opened the box and showed him the lone Arduino board he turned red.</p>
My potentiometers don't fit into my breadboard, so atm i have them taped to the jumper wires, and the wires are plugged into the breadboard, is there a better way?
You can just solder some wires/leads onto the pits too
You could buy trimmers, they are small ones which go on for pcb mount. <br>https://en.wikipedia.org/wiki/Potentiometer
<p>May be better to use a Due since the chip has 10-12-bit ADC/DAC's</p>
Does this work with an Arduino Uno R3?
Yes, there shouldn't be any trouble...
I probably have the wires put into the wrong position then :P <br>Thanks!
hi my friend,, please upload the code for arduino leonardo, thanks, regards from Bogota Colombia
Do you reckon it would be fairly easy to change one of the pots with a photo resistor at all? would any of the code need to change for that?
No code would be needed, ver straight forward. Read this, it might help to wire: <a href="http://www.societyofrobots.com/schematics_photoresistor.shtml" rel="nofollow">www.societyofrobots.com/schematics_photoresistor.shtml</a>
10k pots are fine too. <br> <br>BTW, great project, a lot of fun with just total 2 minutes for both wiring and uploading!!!
Well I finally &quot;Made&quot; this project, took it off the bread board and put it in an old thin client case, the cool thing, is i added a 2 wire red/green light and wen it pulses back and forth between red and green its hypnotizing especially with headphones, then when you adjust more of the pots you can get orange from the light as well. it pretty cool. I wanna getin and play with the code now, that its hardwired! Thanks again guys! <br> <br>Id be interested, in an easy way to ad some depth to this say a delay to one of the headphone out channels. I have and OLD original reverberation made for the home stereo from the 70's but I don't really wanna sacrifice that.
Since all of the pots are working as voltage dividers, they could all be any value, not just 5K.... even different values. Nice work, BTW.
Yep, that is right. Personally I think using 5K is the best value for this project. Thanks.
I tried a few different pot sizes 1K 5k 20k 50K and the only ones that made a significant difference were the 5K. <br>I got 10 5k pots of ebay for a buck so remade this, and it was like a completely different project 100 times cooler. <br>5k really seem to work best, at least on original code, haven't tried the second one yet. anyone have comments on the difference between the two codes? <br>
that code has error this code is compiled <br> <br> <br> <br>// Auduino, the Lo-Fi granular synthesiser <br>// <br>// by Peter Knight, Tinker.it http://tinker.it <br>// <br>// Help: http://code.google.com/p/tinkerit/wiki/Auduino <br>// More help: http://groups.google.com/group/auduino <br>// <br>// Analog in 0: Grain 1 pitch <br>// Analog in 1: Grain 2 decay <br>// Analog in 2: Grain 1 decay <br>// Analog in 3: Grain 2 pitch <br>// Analog in 4: Grain repetition frequency <br>// <br>// Digital 3: Audio out (Digital 11 on ATmega8) <br>// <br>// Changelog: <br>// 19 Nov 2008: Added support for ATmega8 boards <br>// 21 Mar 2009: Added support for ATmega328 boards <br>// 7 Apr 2009: Fixed interrupt vector for ATmega328 boards <br>// 8 Apr 2009: Added support for ATmega1280 boards (Arduino Mega) <br>// 11 Mar 2012: edit code to fit corresponding Fritzing diagram. <br> <br>/* <br>10/07/10 Prodical contributed: <br>- additional mapping modes - diatonic major and minor and pentatonic major and minor <br>- switchable between modes by a single button which cycles through each and differentiates by an LED blinking as per the mode number <br>- a light dependent resistor (LDR) - calibrated in the first five seconds after switching on - replacing the main (grain repetition) frequency pot on a switch (using an external interrupt) with an LED indicator when it&Atilde;&cent;&acirc;‚&not;&acirc;„&cent;s active but which also dims according on the LDR value <br>more details at http://blog.lewissykes.info <br>*/ <br> <br>/* <br> Calibration <br> <br> Demonstrates one techinque for calibrating sensor input. The <br> sensor readings during the first five seconds of the sketch <br> execution define the minimum and maximum of expected values <br> attached to the sensor pin. <br> <br> The sensor minumum and maximum initial values may seem backwards. <br> Initially, you set the minimum high and listen for anything <br> lower, saving it as the new minumum. Likewise, you set the <br> maximum low and listen for anything higher as the new maximum. <br> <br> The circuit: <br> * Analog sensor (potentiometer will do) attached to analog input 0 <br> * LED attached from digital pin 9 to ground <br> <br> created 29 Oct 2008 <br> By David A Mellis <br> Modified 17 Jun 2009 <br> By Tom Igoe <br> <br> http://arduino.cc/en/Tutorial/Calibration <br> <br> This example code is in the public domain. <br> <br> */ <br> <br>// AUDUINO code STARTS <br>#include <br>#include <br> <br>uint16_t syncPhaseAcc; <br>uint16_t syncPhaseInc; <br>uint16_t grainPhaseAcc; <br>uint16_t grainPhaseInc; <br>uint16_t grainAmp; <br>uint8_t grainDecay; <br>uint16_t grain2PhaseAcc; <br>uint16_t grain2PhaseInc; <br>uint16_t grain2Amp; <br>uint8_t grain2Decay; <br> <br>// Map Analogue channels <br>#define SYNC_CONTROL (4) <br>#define GRAIN_FREQ_CONTROL (3) <br>#define GRAIN_DECAY_CONTROL (2) <br>#define GRAIN2_FREQ_CONTROL (1) <br>#define GRAIN2_DECAY_CONTROL (0) <br> <br>// Changing these will also requires rewriting audioOn() <br>#if defined(__AVR_ATmega8__) <br>// <br>// On old ATmega8 boards. <br>// Output is on pin 11 <br>// <br>#define LED_PIN 13 <br>#define LED_PORT PORTB <br>#define LED_BIT 5 <br>#define PWM_PIN 11 <br>#define PWM_VALUE OCR2 <br>#define PWM_INTERRUPT TIMER2_OVF_vect <br>#elif defined(__AVR_ATmega1280__) <br>// <br>// On the Arduino Mega <br>// Output is on pin 3 <br>// <br>#define LED_PIN 13 <br>#define LED_PORT PORTB <br>#define LED_BIT 7 <br>#define PWM_PIN 3 //3 <br>#define PWM_VALUE OCR3C <br>#define PWM_INTERRUPT TIMER3_OVF_vect <br>#else <br>// <br>// For modern ATmega168 and ATmega328 boards <br>// Output is on pin 3 <br>// <br>#define PWM_PIN 3 //3 <br>#define PWM_VALUE OCR2B <br>#define LED_PIN 13 <br>#define LED_PORT PORTB <br>#define LED_BIT 5 <br>#define PWM_INTERRUPT TIMER2_OVF_vect <br>#endif <br>// AUDUINO code ENDS <br> <br> <br>// BUTTON, SWITCH, LDR &amp; LEDs - START <br>// Button <br>#define BUTTON_PIN (6) // the number of the pushbutton pin <br>int buttonValue; // variable for reading the button status <br>int buttonState; // variable to hold the button state <br>int mapMode = 0; // What scale/mapping mode is in use? <br> <br>// LDR <br>//#define LDRSWITCH (4) <br>// switch replaced by external interrupt <br>volatile int LDRswitchState = LOW; <br>#define LDR_PIN (5) <br>#define LDRLED_PIN (9) <br>//Callibration variables <br>int LDRValue = 0; // the sensor value <br>int LDRMin = 1023; // minimum sensor value <br>int LDRMax = 0; // maximum sensor value <br> <br>// PWM_VALUE LED <br>#define FRQLED_PIN (11) // not as consistent as pin 13 <br> <br>// mapmode LED <br>#define mapModeLED_PIN (10) // the number of the LED pin <br>int mapModeLEDState = LOW; // ledState used to set the LED <br>long previousMillis = 0; // will store last time LED was updated <br>int BlinkRate = 5; // no of blinks per second i.e. fps - empirically tested as just slow enough to count <br>int BlinkCount = 0; // variable to store no of blinks <br>int BlinkLoopLength = 14; // err... blink loop length <br> <br>// BUTTON, SWITCH, LDR &amp; LEDs - ENDS <br> <br> <br>// MAPPINGS - START <br>// Smooth logarithmic mapping <br>// <br>uint16_t antilogTable[] = { <br> 64830,64132,63441,62757,62081,61413,60751,60097,59449,58809,58176,57549,56929,56316,55709,55109, <br> 54515,53928,53347,52773,52204,51642,51085,50535,49991,49452,48920,48393,47871,47356,46846,46341, <br> 45842,45348,44859,44376,43898,43425,42958,42495,42037,41584,41136,40693,40255,39821,39392,38968, <br> 38548,38133,37722,37316,36914,36516,36123,35734,35349,34968,34591,34219,33850,33486,33125,32768 <br>}; <br>uint16_t mapPhaseInc(uint16_t input) { <br> return (antilogTable[input &amp; 0x3f]) &gt;&gt; (input &gt;&gt; 6); <br>} <br> <br>// Stepped chromatic mapping <br>// <br>uint16_t midiTable[] = { <br> 0,17,18,19,20,22,23,24,26,27,29,31,32,34,36,38,41,43,46,48,51,54,58,61,65,69,73, <br> 77,82,86,92,97,103,109,115,122,129,137,145,154,163,173,183,194,206,218,231, <br> 244,259,274,291,308,326,346,366,388,411,435,461,489,518,549,581,616,652,691, <br> 732,776,822,871,923,978,1036,1097,1163,1232,1305,1383,1465,1552,1644,1742, <br> 1845,1955,2071,2195,2325,2463,2610,2765,2930,3104,3288,3484,3691,3910,4143, <br> 4389,4650,4927,5220,5530,5859,6207,6577,6968,7382,7821,8286,8779,9301,9854, <br> 10440,11060,11718,12415,13153,13935,14764,15642,16572,17557,18601,19708,20879, <br> 22121,23436,24830,26306,27871 <br>}; <br>uint16_t mapMidi(uint16_t input) { <br> return (midiTable[(1023-input) &gt;&gt; 3]); <br>} <br> <br>//// Stepped Pentatonic mapping <br>// <br>uint16_t pentatonicTable[54] = { <br> 0,19,22,26,29,32,38,43,51,58,65,77,86,103,115,129,154,173,206,231,259,308,346, <br> 411,461,518,616,691,822,923,1036,1232,1383,1644,1845,2071,2463,2765,3288, <br> 3691,4143,4927,5530,6577,7382,8286,9854,11060,13153,14764,16572,19708,22121,26306 <br>}; <br> <br>uint16_t mapPentatonic(uint16_t input) { <br> uint8_t value = (1023-input) / (1024/53); <br> return (pentatonicTable[value]); <br>} <br> <br>// Lewis added - I've got an Excel spreadsheet with these workings out on my blog... <br>// Stepped major Diatonic mapping <br>// <br>uint16_t majordiatonicTable[76] = { <br> 0,17,19,22,23,26,29,32,34,38,43,46,51,58,65,69,77,86,92,103,115,129,137,154,173,183,206,231,259,274,308,346,366, <br> 411,461,518,549,616,691,732,822,923,1036,1097,1232,1383,1465,1644,1845,2071,2195,2463,2765,2930,3288, <br> 3691,4143,4389,4927,5530,5859,6577,7382,8286,8779,9854,11060,11718,13153,14764,16572,17557,19708,22121,23436,26306 <br>}; <br> <br>uint16_t mapmajorDiatonic(uint16_t input) { <br> uint8_t value = (1023-input) / (1024/53); <br> return (majordiatonicTable[value]); <br>} <br> <br>// Stepped minor Diatonic mapping <br>// <br>uint16_t minordiatonicTable[76] = { <br> 0,17,19,20,23,26,27,31,34,38,41,46,51,54,61,69,77,82,92,103,109,122,137,154,163,183,206,218,244,274,308,326,366, <br> 411,435,489,549,616,652,732,822,871,978,1097,1232,1305,1465,1644,1742,1955,2195,2463,2610,2930,3288, <br> 3484,3910,4389,4927,5220,5859,6577,6968,7821,8779,9854,10440,11718,13153,13935,15642,17557,19708,20879,23436,26306 <br>}; <br> <br>uint16_t mapminorDiatonic(uint16_t input) { <br> uint8_t value = (1023-input) / (1024/53); <br> return (minordiatonicTable[value]); <br>} <br> <br>// Stepped major Pentatonic mapping <br>// <br>uint16_t majorpentatonicTable[55] = { <br> 0,17,19,22,26,29,34,38,43,51,58,69,77,86,103,115,137,154,173,206,231,274,308,346, <br> 411,461,549,616,691,822,923,1097,1232,1383,1644,1845,2195,2463,2765,3288, <br> 3691,4389,4927,5530,6577,7382,8779,9854,11060,13153,14764,17557,19708,22121,26306 <br>}; <br> <br>uint16_t mapmajorPentatonic(uint16_t input) { <br> uint8_t value = (1023-input) / (1024/53); <br> return (majorpentatonicTable[value]); <br>} <br> <br>// Stepped minor Pentatonic mapping <br>// <br>uint16_t minorpentatonicTable[55] = { <br> 0,17,20,23,26,31,34,41,46,51,61,69,82,92,103,122,137,163,183,206,244,274,326,366, <br> 411,489,549,652,732,822,978,1097,1305,1465,1644,1955,2195,2610,2930,3288, <br> 3910,4389,5220,5859,6577,7821,8779,10440,11718,13153,15642,17557,20879,23436,26306 <br>}; <br> <br>uint16_t mapminorPentatonic(uint16_t input) { <br> uint8_t value = (1023-input) / (1024/53); <br> return (pentatonicTable[value]); <br>} <br>// MAPPINGS - END <br> <br> <br>void audioOn() { <br>#if defined(__AVR_ATmega8__) <br> // ATmega8 has different registers <br> TCCR2 = _BV(WGM20) | _BV(COM21) | _BV(CS20); <br> TIMSK = _BV(TOIE2); <br>#elif defined(__AVR_ATmega1280__) <br> TCCR3A = _BV(COM3C1) | _BV(WGM30); <br> TCCR3B = _BV(CS30); <br> TIMSK3 = _BV(TOIE3); <br>#else <br> // Set up PWM to 31.25kHz, phase accurate <br> TCCR2A = _BV(COM2B1) | _BV(WGM20); <br> TCCR2B = _BV(CS20); <br> TIMSK2 = _BV(TOIE2); <br>#endif <br>} <br> <br> <br>void setup() { <br> <br> pinMode(PWM_PIN,OUTPUT); <br> audioOn(); <br> pinMode(LDRLED_PIN,OUTPUT); <br> pinMode(FRQLED_PIN,OUTPUT); <br> pinMode(mapModeLED_PIN,OUTPUT); <br> pinMode(BUTTON_PIN,INPUT); <br> attachInterrupt(0, LDRswitched, CHANGE); <br> <br> // Calibration <br> //Serial.begin(9600); <br> // turn on LED to signal the start of the calibration period: <br> pinMode(9, OUTPUT); <br> digitalWrite(9, HIGH); <br> // calibrate during the first five seconds <br> while (millis() &lt; 5000) { <br> LDRValue = analogRead(LDR_PIN); <br> // record the maximum sensor value <br> if (LDRValue &gt; LDRMax) { <br> LDRMax = LDRValue; <br> } <br> // record the minimum sensor value <br> if (LDRValue &lt; LDRMin) { <br> LDRMin = LDRValue; <br> } <br> } <br> // signal the end of the calibration period <br> digitalWrite(9, LOW); <br> // END calibration code <br> <br>} <br> <br> <br>void LDRswitched() <br>{ <br> LDRswitchState = !LDRswitchState; <br>} <br> <br> <br>void loop() { <br> // The loop is pretty simple - it just updates the parameters for the oscillators. <br> // <br> // Avoid using any functions that make extensive use of interrupts, or turn interrupts off. <br> // They will cause clicks and poops in the audio. <br> <br> // Smooth frequency mapping <br> //syncPhaseInc = mapPhaseInc(analogRead(SYNC_CONTROL)) / 4; <br> <br> // Stepped mapping to MIDI notes: C, Db, D, Eb, E, F... <br> //syncPhaseInc = mapMidi(analogRead(SYNC_CONTROL)); <br> <br> // // Stepped pentatonic mapping: D, E, G, A, B <br> // syncPhaseInc = mapPentatonic(analogRead(SYNC_CONTROL)); <br> <br> // could add switch here to choose between midiIn() and the twisty-pot pitch control <br> <br> //BEGIN Calibration <br> // read the sensor: <br> LDRValue = analogRead(LDR_PIN); <br> // apply the calibration to the sensor reading <br> LDRValue = map(LDRValue, LDRMin, LDRMax, 0, 1023); <br> // in case the sensor value is outside the range seen during calibration <br> LDRValue = constrain(LDRValue, 0, 1023); <br> // // fade the LED using the calibrated value: (this moved below) <br> // analogWrite(LDRLED_PIN, LDRValue); <br> // Serial.println(LDRValue); <br> //END Calibration <br> <br> // button presses cycle through scales/mapping modes <br> buttonValue = digitalRead(BUTTON_PIN); // read input value and store it in val <br> if (buttonValue != buttonState) { // the button state has changed! <br> if (buttonValue == 0) { // check if the button is pressed <br> if (mapMode == 0) { // if set to smooth logarithmic mapping <br> mapMode = 1; // switch to stepped chromatic mapping <br> } <br> else { <br> if (mapMode == 1) { // if stepped chromatic mapping <br> mapMode = 2; // switch to stepped major Diatonic mapping <br> } <br> else { <br> if (mapMode == 2) { // if stepped major Diatonic mapping <br> mapMode = 3; // switch to stepped minor Diatonic mapping <br> } <br> else { <br> if (mapMode == 3) { // if stepped minor Diatonic mapping <br> mapMode = 4; // switch to stepped major Pentatonic mapping <br> } <br> else { <br> if (mapMode == 4) { // if stepped major Pentatonic mapping <br> mapMode = 5; // switch to stepped minor Pentatonic mapping <br> } <br> else { <br> if (mapMode == 5) { // if stepped major Pentatonic mapping <br> mapMode = 0; // switch back to smooth logarithmic mapping <br> } <br> } <br> } <br> } <br> } <br> } <br> } <br> buttonState = buttonValue; // save the new state in our variable <br> } <br> <br> // mapMode LED indicator - blinks number of scale/mapping mode on a fixed 'frame' cycle <br> if (millis() - previousMillis &gt; 1000/BlinkRate) <br> { <br> BlinkCount = BlinkCount + 1; <br> // save the last time you blinked the LED <br> previousMillis = millis(); <br> digitalWrite(mapModeLED_PIN, LOW); <br> if (BlinkCount &lt;= (mapMode+1)*2) <br> { <br> //if the LED is off turn it on and vice-versa: <br> if (mapModeLEDState == LOW) <br> { <br> mapModeLEDState = HIGH; <br> } <br> else{ <br> mapModeLEDState = LOW; <br> } <br> // set the LED with the ledState of the variable: <br> digitalWrite(mapModeLED_PIN, mapModeLEDState); <br> } <br> // resets Blink loop after 14 blinks <br> else if (BlinkCount &gt;= BlinkLoopLength) <br> { <br> BlinkCount = 0; <br> } <br> //debug <br> //Serial.println(BlinkCount); <br> } <br> <br> //Map modes to select with button. LED blinks as per mode currently in use <br> //selects which array to pull data from to get SyncPhaseInc <br> //1. Smooth logarithmic mapping <br> if (mapMode == 0) { <br> if (LDRswitchState == HIGH) { <br> syncPhaseInc = mapPhaseInc(1023-LDRValue) / 4; <br> analogWrite(LDRLED_PIN, LDRValue); <br> } <br> else <br> { <br> syncPhaseInc = mapPhaseInc(analogRead(SYNC_CONTROL)) / 4; <br> digitalWrite(LDRLED_PIN, LOW); <br> } <br> } <br> //2. Stepped chromatic mapping to MIDI notes: C,C#,D,Eb,F,F#,G,Ab,A,Bb,B <br> if (mapMode == 1) { <br> if (LDRswitchState == HIGH) { <br> syncPhaseInc = mapMidi(1023-LDRValue); <br> analogWrite(LDRLED_PIN, LDRValue); <br> } <br> else <br> { <br> syncPhaseInc = mapMidi(analogRead(SYNC_CONTROL)); <br> digitalWrite(LDRLED_PIN, LOW); <br> } <br> } <br> //3. Stepped major Diatonic mapping: C,D,E,F,G,A,B <br> if (mapMode == 2) { <br> if (LDRswitchState == HIGH) { <br> syncPhaseInc = mapmajorDiatonic(1023-LDRValue); <br> analogWrite(LDRLED_PIN, LDRValue); <br> } <br> else <br> { <br> syncPhaseInc = mapmajorDiatonic(analogRead(SYNC_CONTROL)); <br> digitalWrite(LDRLED_PIN, LOW); <br> } <br> } <br> //4. Stepped minor Diatonic mapping: C,D,Eb,F,G,Ab,Bb <br> if (mapMode == 3) { <br> if (LDRswitchState == HIGH) { <br> syncPhaseInc = mapminorDiatonic(1023-LDRValue); <br> analogWrite(LDRLED_PIN, LDRValue); <br> } <br> else <br> { <br> syncPhaseInc = mapminorDiatonic(analogRead(SYNC_CONTROL)); <br> digitalWrite(LDRLED_PIN, LOW); <br> } <br> } <br> //5. Stepped major Pentatonic mapping <br> if (mapMode == 4) { <br> if (LDRswitchState == HIGH) { <br> syncPhaseInc = mapmajorPentatonic(1023-LDRValue); <br> analogWrite(LDRLED_PIN, LDRValue); <br> } <br> else <br> { <br> syncPhaseInc = mapmajorPentatonic(analogRead(SYNC_CONTROL)); <br> digitalWrite(LDRLED_PIN, LOW); <br> } <br> } <br> //6. Stepped major Diatonic mapping <br> if (mapMode == 5) { <br> if (LDRswitchState == HIGH) { <br> syncPhaseInc = mapminorPentatonic(1023-LDRValue); <br> analogWrite(LDRLED_PIN, LDRValue); <br> } <br> else <br> { <br> syncPhaseInc = mapminorPentatonic(analogRead(SYNC_CONTROL)); <br> digitalWrite(LDRLED_PIN, LOW); <br> } <br> } <br> <br> //input from pots <br> grainPhaseInc = mapPhaseInc(analogRead(GRAIN_FREQ_CONTROL)) / 2; <br> grainDecay = analogRead(GRAIN_DECAY_CONTROL) / 8; <br> grain2PhaseInc = mapPhaseInc(analogRead(GRAIN2_FREQ_CONTROL)) / 2; <br> grain2Decay = analogRead(GRAIN2_DECAY_CONTROL) / 4; <br> <br> digitalWrite(FRQLED_PIN, PWM_VALUE); <br> <br>} <br> <br> <br>SIGNAL(PWM_INTERRUPT) <br>{ <br> uint8_t value; <br> uint16_t output; <br> <br> syncPhaseAcc += syncPhaseInc; <br> if (syncPhaseAcc &lt; syncPhaseInc) { <br> // Time to start the next grain <br> grainPhaseAcc = 0; <br> grainAmp = 0x7fff; <br> grain2PhaseAcc = 0; <br> grain2Amp = 0x7fff; <br> LED_PORT ^= 1 &lt;&lt; LED_BIT; // Faster than using digitalWrite <br> } <br> <br> // Increment the phase of the grain oscillators <br> grainPhaseAcc += grainPhaseInc; <br> grain2PhaseAcc += grain2PhaseInc; <br> <br> // Convert phase into a triangle wave <br> value = (grainPhaseAcc &gt;&gt; 7) &amp; 0xff; <br> if (grainPhaseAcc &amp; 0x8000) value = ~value; <br> // Multiply by current grain amplitude to get sample <br> output = value * (grainAmp &gt;&gt; 8); <br> <br> // Repeat for second grain <br> value = (grain2PhaseAcc &gt;&gt; 7) &amp; 0xff; <br> if (grain2PhaseAcc &amp; 0x8000) value = ~value; <br> output += value * (grain2Amp &gt;&gt; 8); <br> <br> // Make the grain amplitudes decay by a factor every sample (exponential decay) <br> grainAmp -= (grainAmp &gt;&gt; 8) * grainDecay; <br> grain2Amp -= (grain2Amp &gt;&gt; 8) * grain2Decay; <br> <br> // Scale output to the available range, clipping if necessary <br> output &gt;&gt;= 9; <br> if (output &gt; 255) output = 255; <br> <br> // Output to PWM (this is faster than using analogWrite) <br> PWM_VALUE = output; <br>} <br>

About This Instructable




Bio: Im 16 and love electronics! I love music; writing music and playing piano. I have fun with microcontrollers and playing with other stuff too. There ... More »
More by TobaTobias:Chaos Nand Synth Arduino Step Sequencer Mini metronome 
Add instructable to: