Following my first interactive embroidery, the LilyKorg, I decided to work with the idea of creating a bit more complex soft-circuit system, incorporating buttons, a potentiometer, a switch and also a Jack output so that I can connect the embroidery to an amplifier, a console and effects pedals in order to be able to use it as a musical instrument.

I found my inspiration in the design of Roland' s TR-909 drum machine combined with the LilyPad' s technology, hence I created my own RolandPad.

This is the source code:

/* RolandPad
by Afroditi Psarra
February 2012*/

#include "pitches.h" //include public constants NOTES

//declare variables
// melody buttonA
int melodyA[] = {
NOTE_B2, 0, NOTE_GS1, 0, NOTE_B2, 0, NOTE_A1, 0 };

// note durations: 4 = quarter note, 8 = eighth note, etc.:
int noteDurationsA[] = {
8, 8, 8, 8, 8, 8, 8, 8 };

//melody buttonB
int melodyB[] = {
NOTE_E2, NOTE_E2, NOTE_E2, NOTE_E2, 0, NOTE_F2, NOTE_F2, NOTE_F2, NOTE_F2, 0 };

// note durations: 4 = quarter note, 8 = eighth note, etc.:
int noteDurationsB[] = {
4, 4, 4, 4, 2, 4, 4, 4, 4, 2 };

const int ledPin = 13;// LED is connected to digital pin 13
const int speakerPin = 5;// speaker connected to digital pin 5
const int switchPin = 10;// switch connected to digital pin 11
const int potPin = A2;// potentiometer connected to analog pin 2

int switchValue;// variable to keep track of when switch is pressed
int potValue;// variable to store the value coming from the potentiometer
int delayValue; // variable that uses the potValue to control the melody's tempo

const int buttonA = 6; //buttonA connected to digital pin 6
const int buttonB = 9; //buttonB connected to digital pin 9

// variables will change:
int buttonAState = 0; // variable for reading the buttonA status
int buttonBState = 0; // variable for reading the buttonB status

void setup()
{
pinMode(ledPin, OUTPUT);// sets the ledPin to be an output
pinMode(speakerPin, OUTPUT); // sets the speakerPin to be an output
pinMode(buttonA, INPUT); // sets buttonA to be an intput
pinMode(buttonB, INPUT); // sets buttonB to be an intput
digitalWrite(switchPin, LOW); // sets the default (unpressed) state of switchPin to HIGH
Serial.begin(9600);//initialize the serial port
}

void loop() {

potValue = analogRead(potPin);// read the value from the sensor
delayValue = map(potValue, 0, 1023, 0, 1000); //map the value from the sensor

Serial.print("\t potValue = ");
Serial.print(potValue);// send that value to the computer
Serial.print("\t delayValue = ");
Serial.println(delayValue);

// read the state of the buttonA value:
buttonAState = digitalRead(buttonA);
Serial.print("buttonA = ");
Serial.print(buttonAState);

// check if the buttonA is pressed.
// if it is, the buttonAState is HIGH:
if (buttonAState == HIGH) {
// turn LED on:
digitalWrite(ledPin, HIGH);
for (int thisNote = 0; thisNote < 8; thisNote++) {

// to calculate the note duration, take one second
// divided by the note type.
//e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
int noteDurationA = 1000/noteDurationsA[thisNote];
tone(speakerPin, melodyA[thisNote],noteDurationA);
delay(delayValue);
}
}
else if (buttonAState == LOW) {
// turn LED off:
digitalWrite(ledPin, LOW);
}

// read the state of the buttonB value:
buttonBState = digitalRead(buttonB);
Serial.print("\t buttonB = ");
Serial.print(buttonBState);

if (buttonBState == HIGH) {
// turn LED on:
digitalWrite(ledPin, HIGH);
for (int thisNote = 0; thisNote < 10; thisNote++) {

// to calculate the note duration, take one second
// divided by the note type.
//e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
int noteDurationB = 1000/noteDurationsB[thisNote];
tone(5, melodyB[thisNote],noteDurationB);
delay(delayValue);
}
}
else if (buttonBState == LOW) {
// turn LED off:
digitalWrite(ledPin, LOW);
}

switchValue = digitalRead(switchPin);// check to see if the switch is pressed
Serial.print("\t switch = ");
Serial.println(switchValue);
if (switchValue == HIGH) {// if the switch is pressed then,
digitalWrite(ledPin, HIGH);// turn the LED on
beep(speakerPin, potValue * 4 + 500, delayValue); // sound
delay(delayValue);
}
else {// otherwise,
digitalWrite(ledPin, LOW);// turn the LED off
}
}

void beep (unsigned char speakerPin, int frequencyInHertz, long timeInMilliseconds) // the sound producing function
{
int x;
long delayAmount = (long)(1000000/frequencyInHertz);
long loopTime = (long)((timeInMilliseconds*1000)/(delayAmount*2));
for (x=0;x {
digitalWrite(speakerPin,HIGH);
delayMicroseconds(delayAmount);
digitalWrite(speakerPin,LOW);
delayMicroseconds(delayAmount);
}
}

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.