not really textile related exactly, but I do intend to plug whatever fabric I happen to make on the loom this week into this code and use it to generate sound.
this is the code
i'm really just putting this up here so I have it in another place in case I lose it because I'll no doubt forget how i did this and have to figure out from scratch how i did it if i lose the file.
the main thing about this is that it doesn't matter that much really what resistive range I can get on any particular textile sensor that I create now because I'm not using the actual value of the resistor resistance (ugh, whatever) to enter values into the program. what i'm doing is mapping the range of the whole resistor to a different variable. so whether the range of the resistor is 0-10000ohm or 0-200000ohm it doesn't matter, I can just map those values to the range of 0-1000
With any luck the cloth will work out and I can make a little sequencer control panel out of cloth.
Arduino is so much fun.
Wish my dog would relax though.
//variable pitch square wave generator
//reads value from potentiometer
//maps said value to provide Microsecond delay
//23.01.12
//Andrew Kieran
int potOne = 0; // timer pot
int potTwo = 0; // step one pot
int potThree = 0; // step two pot
int potFour = 0; // step threepot
int potFive = 0; // step four pot
int potOneOut = 0; // mapped value from pot one, timer repeat
int potTwoOut = 0; // mapped value from pot two, step two frequency
int potThreeOut = 0; //mapped value from pot three, step three freq
int potFourOut = 0;
int potFiveOut = 0;
const int potOnePin = A0;
const int potTwoPin = A1;
const int potThreePin = A2;
const int potFourPin = A3;
const int potFivePin = A4;
const int outPin = 9;
unsigned long Timer; // hmmmmmm
void setup() {
pinMode (potOne, INPUT);
pinMode (potTwo, INPUT);
pinMode (potThree, INPUT);
pinMode (potFour, INPUT);
pinMode (potFive, INPUT);
pinMode (outPin, OUTPUT);
}
void loop () {
potOne = analogRead(potOnePin);
potOneOut = map(potOne, 0, 1000, 0, 1000);
Timer = millis();
stepOne();
Timer = millis();
stepTwo();
Timer = millis();
stepThree();
Timer = millis();
stepFour();
}
void stepOne(){
while (millis()-Timer<=potOneOut){
potTwo = analogRead(potTwoPin);
potTwoOut = map(potTwo, 0, 1000, 0, 5000);
digitalWrite(outPin, HIGH);
delayMicroseconds(potTwoOut);
digitalWrite(outPin, LOW);
delayMicroseconds(potTwoOut);
}
}
void stepTwo(){
while (millis()-Timer<=potOneOut){
potThree = analogRead(potThreePin);
potThreeOut = map(potThree, 0, 1000, 0, 5000);
digitalWrite(outPin, HIGH);
delayMicroseconds(potThreeOut);
digitalWrite(outPin, LOW);
delayMicroseconds(potThreeOut);
}
}
void stepThree(){
while (millis()-Timer<=potOneOut){
potFour = analogRead(potFourPin);
potFourOut = map(potFour, 0, 1000, 0, 5000);
digitalWrite(outPin, HIGH);
delayMicroseconds(potFourOut);
digitalWrite(outPin, LOW);
delayMicroseconds(potFourOut);
}
}
void stepFour(){
while (millis()-Timer<=potOneOut){
potFive = analogRead(potFivePin);
potFiveOut = map(potFive, 0, 1000, 0, 5000);
digitalWrite(outPin, HIGH);
delayMicroseconds(potFiveOut);
digitalWrite(outPin, LOW);
delayMicroseconds(potFiveOut);
}
}
this is the code
i'm really just putting this up here so I have it in another place in case I lose it because I'll no doubt forget how i did this and have to figure out from scratch how i did it if i lose the file.
the main thing about this is that it doesn't matter that much really what resistive range I can get on any particular textile sensor that I create now because I'm not using the actual value of the resistor resistance (ugh, whatever) to enter values into the program. what i'm doing is mapping the range of the whole resistor to a different variable. so whether the range of the resistor is 0-10000ohm or 0-200000ohm it doesn't matter, I can just map those values to the range of 0-1000
With any luck the cloth will work out and I can make a little sequencer control panel out of cloth.
Arduino is so much fun.
Wish my dog would relax though.
//variable pitch square wave generator
//reads value from potentiometer
//maps said value to provide Microsecond delay
//23.01.12
//Andrew Kieran
int potOne = 0; // timer pot
int potTwo = 0; // step one pot
int potThree = 0; // step two pot
int potFour = 0; // step threepot
int potFive = 0; // step four pot
int potOneOut = 0; // mapped value from pot one, timer repeat
int potTwoOut = 0; // mapped value from pot two, step two frequency
int potThreeOut = 0; //mapped value from pot three, step three freq
int potFourOut = 0;
int potFiveOut = 0;
const int potOnePin = A0;
const int potTwoPin = A1;
const int potThreePin = A2;
const int potFourPin = A3;
const int potFivePin = A4;
const int outPin = 9;
unsigned long Timer; // hmmmmmm
void setup() {
pinMode (potOne, INPUT);
pinMode (potTwo, INPUT);
pinMode (potThree, INPUT);
pinMode (potFour, INPUT);
pinMode (potFive, INPUT);
pinMode (outPin, OUTPUT);
}
void loop () {
potOne = analogRead(potOnePin);
potOneOut = map(potOne, 0, 1000, 0, 1000);
Timer = millis();
stepOne();
Timer = millis();
stepTwo();
Timer = millis();
stepThree();
Timer = millis();
stepFour();
}
void stepOne(){
while (millis()-Timer<=potOneOut){
potTwo = analogRead(potTwoPin);
potTwoOut = map(potTwo, 0, 1000, 0, 5000);
digitalWrite(outPin, HIGH);
delayMicroseconds(potTwoOut);
digitalWrite(outPin, LOW);
delayMicroseconds(potTwoOut);
}
}
void stepTwo(){
while (millis()-Timer<=potOneOut){
potThree = analogRead(potThreePin);
potThreeOut = map(potThree, 0, 1000, 0, 5000);
digitalWrite(outPin, HIGH);
delayMicroseconds(potThreeOut);
digitalWrite(outPin, LOW);
delayMicroseconds(potThreeOut);
}
}
void stepThree(){
while (millis()-Timer<=potOneOut){
potFour = analogRead(potFourPin);
potFourOut = map(potFour, 0, 1000, 0, 5000);
digitalWrite(outPin, HIGH);
delayMicroseconds(potFourOut);
digitalWrite(outPin, LOW);
delayMicroseconds(potFourOut);
}
}
void stepFour(){
while (millis()-Timer<=potOneOut){
potFive = analogRead(potFivePin);
potFiveOut = map(potFive, 0, 1000, 0, 5000);
digitalWrite(outPin, HIGH);
delayMicroseconds(potFiveOut);
digitalWrite(outPin, LOW);
delayMicroseconds(potFiveOut);
}
}
Comments