BadgerHack: Synth Add-On Kit
Contributors:
Nick Poole
Code
Plug the USB side of your BadgerStick into your computer. Make sure "BadgerStick" and the associated COM port are selected in the window below. Click "Run on Arduino."
Note: If you have the Redstick, make sure to instead selecte "Arduino Uno" in the window below.
Copy the code below, and upload it through the Arduino IDE.
/*BadgerSynth Example Sketch February 2016 Written by Nick Poole SparkFun Electronics Code is released under the MIT License. */ int x = 2; int osc1 = 0; int osc2 = 0; int ran = 0; int tempo = 0; int note; bool event = 0; void setup() { // Setup all of the DIP Switch pins as Inputs for(int i = 0; i<10; i++){ pinMode(i, INPUT); digitalWrite(i, 1); } } void loop() { // Read all of the potentiometers tempo = analogRead(POT_A) * 10; osc1 = map(analogRead(POT_B), 0, 1023, 200, 6000); osc2 = map(analogRead(POT_C), 0, 1023, 0, 1000); ran = analogRead(POT_D)/2; if(x==10){x=2;} // Iterate through each step on our DIP Switch for(int y = 0; y<tempo; y++){ // Time each event to trigger on tempo if(digitalRead(x)==0){ if(event == 0){ note = random(osc1-ran, osc1+ran); // Allow for randomness to be set tone(SPEAKER, note, osc2); // Create our tone event = 1;} } else{noTone(SPEAKER);} // If the DIP Switch is off, shut up for a step } x++; event = 0; }
This code steps through each pin on the DIP switch, reading the input to the BadgerStick. If a switch is open, the BadgerStick will make a noise based on the potentiometer inputs. Changing the potentiometers will change the random tones created by the BadgerStick.