Updates from minho Toggle Comment Threads | Keyboard Shortcuts
-
minho
-
minho
Minho Illusion of Life Project
1) My code is based on the first code of this link (http://www.arduino.cc/en/Tutorial/PlayMelody), I added melody arrays, then used switch and case object and If function.
with If function it gets time line each dark an light situation has 3 steps. I also use map function, it controls time delay, so get more interaction with light.
2) I think this structure what I made for my bug would be pretty useful for later, whenever I make things has a timeline and reaction by sensor.
-
minho
Charger scorpion
He has solar panel body and battery organs, charging by light. When he gets full charged, his poisonous tail emits light.
Charging speed depends on power of light, brighter light charges it faster with reaction. He dies in dark.
#define v 18000
#define x 10000
#define z 8000
#define c 3830 // 261 Hz
#define d 3400 // 294 Hz
#define e 3038 // 329 Hz
#define f 2864 // 349 Hz
#define g 2550 // 392 Hz
#define a 2272 // 440 Hz
#define b 2028 // 493 Hz
#define C 1912 // 523 Hz
#define D 1680
#define E 1500
#define F 1350
#define G 1200
#define A 1050
#define B 912
// Define a special note, ‘R’, to represent a rest
#define R 0// SETUP ============================================
// Set up speaker on a PWM pin (digital 9, 10 or 11)
int speakerOut = 9;
// Do we want debugging on serial out? 1 for yes, 0 for no
int DEBUG = 1;int photocellPin = 0; // the cell and 10K pulldown are connected to a0
int photocellReading; // the analog reading from the sensor divider
int LEDpin = 11; // connect Red LED to pin 11 (PWM pin)
int LEDbrightness;
int growspeed;
int bN = 0;
int bNcount = 0;
int bNcount2 = 0;void setup() {
pinMode(speakerOut, OUTPUT);
if (DEBUG) {
Serial.begin(9600); // Set serial out if we want debugging
}
}// MELODY and TIMING =======================================
// melody[] is an array of notes, accompanied by beats[],
// which sets each note’s relative length (higher #, longer note)
int hellom[] = {c, c};
int beats[] = {16, 64};
int dyingm[] = { v, R, z, v };
int beats2[] = { 200, 8, 8, 32 };
int happym[] = { c, C, g, e, C, g, z, e, z, c, C, g, f, C, g, z, f, z, c, C, g, e, C, g, z, e, z, d, e, f, z, f, g, g, z, g, a, a, z, C, R};
int beats3[] = { 16, 16, 16, 16, 8, 8, 16, 16, 16, 16, 16, 16, 16, 8, 8, 16, 16, 16, 16, 16, 16, 16, 8, 8, 16, 16, 16, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 16, 16};
int sadm[] = {z, x, z, z, x, x};
int beats4[] = {36, 36, 36, 36, 36, 200};
int yesm[] = {d, b, E};
int beats5[] = {8, 16, 32};
int nom[] = {B, B, B, B, B, B};
int beats6[] = {8, 8, 8, 8, 8, 8};int MAX_COUNT = sizeof(hellom) / 2;
int MAX_COUNT2 = sizeof(dyingm) / 2;
int MAX_COUNT3 = sizeof(happym) / 2;
int MAX_COUNT4 = sizeof(sadm) / 2;
int MAX_COUNT5 = sizeof(yesm) / 2;
int MAX_COUNT6 = sizeof(nom) / 2;// Melody length, for looping.// Set overall tempo
long tempo = 10000;
// Set length of pause between notes
int pause = 1000;
// Loop variable to increase Rest length
int rest_count = 100; //<-BLETCHEROUS HACK; See NOTES// Initialize core variables
int tone1 = 0;
int beat = 0;
long duration = 0;// PLAY tone1 ==============================================
// Pulse the speaker to play a tone1 for a particular duration
void playtone1() {
long elapsed_time = 0;
if (tone1 > 0) { // if this isn’t a Rest beat, while the tone1 has
// played less long than ‘duration’, pulse speaker HIGH and LOW
while (elapsed_time < duration) {digitalWrite(speakerOut,HIGH);
delayMicroseconds(tone1 / 2);// DOWN
digitalWrite(speakerOut, LOW);
delayMicroseconds(tone1 / 2);// Keep track of how long we pulsed
elapsed_time += (tone1);
}
}
else { // Rest beat; loop times delay
for (int j = 0; j < rest_count; j++) { // See NOTE on rest_count
delayMicroseconds(duration);
}
}
}// LET THE WILD RUMPUS BEGIN =============================
void loop() {
// play each sound in order, with a pause between each one.
photocellReading = analogRead(photocellPin);Serial.print(“Analog reading = “);
Serial.println(photocellReading);
Serial.println( growspeed);
Serial.println(bNcount);
Serial.println(bNcount2);LEDbrightness = 255;
growspeed = map(photocellReading,0, 1023, 10000, 2000);
if(photocellReading>300){
bNcount2 = 0;
bN = 0;
bNcount = bNcount +1;
if(bNcount == 4){
bN= 2;
}
if(bNcount == 5){
bN= 1 ;
bNcount = 0;
}}
if(photocellReading<300){
bNcount = 0;
bN = 4;
bNcount2 = bNcount2 +1;
if(bNcount2 == 4){
bN= 6;
}
if(bNcount2 == 5){
bN= 5 ;
bNcount2 = 0;
}}
switch (bN) {
case 0:
analogWrite(LEDpin, LOW);
hello();
break;case 1:
analogWrite(LEDpin, LEDbrightness);
happy();
break;case 2:
yes();
break;case 3:
// game4();
break;case 4:
analogWrite(LEDpin, LOW);
no();
break;case 5:
analogWrite(LEDpin, LOW);
dying();
break;case 6:
analogWrite(LEDpin, LOW);
sad();break;
}
}
void hello() {
// Set up a counter to pull from melody[] and beats[]
for (int i=0; i<MAX_COUNT; i++) {
tone1 = hellom[i];
beat = beats[i];duration = beat * tempo; // Set up timing
playtone1();
// A pause between notes…
delayMicroseconds(pause);
//noTone(speakerOut);}
delay(growspeed);
}void dying() {
// Set up a counter to pull from melody[] and beats[]
for (int i=0; i<MAX_COUNT2; i++) {
tone1 = dyingm[i];
beat = beats2[i];duration = beat * tempo; // Set up timing
playtone1();
// A pause between notes…
delayMicroseconds(pause);
//noTone(speakerOut);}
delay(10000);
}void happy() {
// Set up a counter to pull from melody[] and beats[]
for (int i=0; i<MAX_COUNT3; i++) {
tone1 = happym[i];
beat = beats3[i];duration = beat * tempo; // Set up timing
playtone1();
// A pause between notes…
delayMicroseconds(pause);
//noTone(speakerOut);}
delay(8000);
}void sad() {
// Set up a counter to pull from melody[] and beats[]
for (int i=0; i<MAX_COUNT4; i++) {
tone1 = sadm[i];
beat = beats4[i];duration = beat * tempo; // Set up timing
playtone1();
// A pause between notes…
delayMicroseconds(pause);
//noTone(speakerOut);}
delay(2000);
}void yes() {
// Set up a counter to pull from melody[] and beats[]
for (int i=0; i<MAX_COUNT5; i++) {
tone1 = yesm[i];
beat = beats5[i];duration = beat * tempo; // Set up timing
playtone1();
// A pause between notes…
delayMicroseconds(pause);
//noTone(speakerOut);}
delay(growspeed);
}void no() {
// Set up a counter to pull from melody[] and beats[]
for (int i=0; i<MAX_COUNT6; i++) {
tone1 = nom[i];
beat = beats6[i];duration = beat * tempo; // Set up timing
playtone1();
// A pause between notes…
delayMicroseconds(pause);
//noTone(speakerOut);}
delay(2000);
}
minho
Emotional tones
http://a.parsons.edu/~kimm541/DSC_4228.MOV
#define v 18000
#define x 10000
#define z 8000
#define c 3830 // 261 Hz
#define d 3400 // 294 Hz
#define e 3038 // 329 Hz
#define f 2864 // 349 Hz
#define g 2550 // 392 Hz
#define a 2272 // 440 Hz
#define b 2028 // 493 Hz
#define C 1912 // 523 Hz
#define D 1680
#define E 1500
#define F 1350
#define G 1200
#define A 1050
#define B 912
// Define a special note, ‘R’, to represent a rest
#define R 0
// SETUP ============================================
// Set up speaker on a PWM pin (digital 9, 10 or 11)
int speakerOut = 9;
// Do we want debugging on serial out? 1 for yes, 0 for no
int DEBUG = 1;
void setup() {
pinMode(speakerOut, OUTPUT);
if (DEBUG) {
Serial.begin(9600); // Set serial out if we want debugging
}
}
// MELODY and TIMING =======================================
// melody[] is an array of notes, accompanied by beats[],
// which sets each note’s relative length (higher #, longer note)
int hellom[] = {c, c};
int beats[] = {16, 64};
int dyingm[] = { v, R, z, v };
int beats2[] = { 200, 8, 8, 32 };
int happym[] = { c, C, g, e, C, g, z, e, z, c, C, g, f, C, g, z, f, z, c, C, g, e, C, g, z, e, z, d, e, f, z, f, g, g, z, g, a, a, z, C, R};
int beats3[] = { 16, 16, 16, 16, 8, 8, 16, 16, 16, 16, 16, 16, 16, 8, 8, 16, 16, 16, 16, 16, 16, 16, 8, 8, 16, 16, 16, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 16, 16};
int sadm[] = {z, x, z, z, x, x};
int beats4[] = {36, 36, 36, 36, 36, 200};
int yesm[] = {d, b, E};
int beats5[] = {8, 16, 32};
int nom[] = {B, B, B, B, B, B};
int beats6[] = {8, 8, 8, 8, 8, 8};
int MAX_COUNT = sizeof(hellom) / 2;
int MAX_COUNT2 = sizeof(dyingm) / 2;
int MAX_COUNT3 = sizeof(happym) / 2;
int MAX_COUNT4 = sizeof(sadm) / 2;
int MAX_COUNT5 = sizeof(yesm) / 2;
int MAX_COUNT6 = sizeof(nom) / 2;// Melody length, for looping.
// Set overall tempo
long tempo = 10000;
// Set length of pause between notes
int pause = 1000;
// Loop variable to increase Rest length
int rest_count = 100; //<-BLETCHEROUS HACK; See NOTES
// Initialize core variables
int tone1 = 0;
int beat = 0;
long duration = 0;
// PLAY tone1 ==============================================
// Pulse the speaker to play a tone1 for a particular duration
void playtone1() {
long elapsed_time = 0;
if (tone1 > 0) { // if this isn’t a Rest beat, while the tone1 has
// played less long than ‘duration’, pulse speaker HIGH and LOW
while (elapsed_time < duration) {
digitalWrite(speakerOut,HIGH);
delayMicroseconds(tone1 / 2);
// DOWN
digitalWrite(speakerOut, LOW);
delayMicroseconds(tone1 / 2);
// Keep track of how long we pulsed
elapsed_time += (tone1);
}
}
else { // Rest beat; loop times delay
for (int j = 0; j < rest_count; j++) { // See NOTE on rest_count
delayMicroseconds(duration);
}
}
}
// LET THE WILD RUMPUS BEGIN =============================
void loop() {
// play each sound in order, with a pause between each one.
delay(3000);
hello();
delay(3000);
dying();
delay(3000);
happy();
delay(3000);
sad();
delay(3000);
yes();
delay(3000);
no();
delay(5000);
}
void hello() {
// Set up a counter to pull from melody[] and beats[]
for (int i=0; i<MAX_COUNT; i++) {
tone1 = hellom[i];
beat = beats[i];
duration = beat * tempo; // Set up timing
playtone1();
// A pause between notes…
delayMicroseconds(pause);
//noTone(speakerOut);
}
}
void dying() {
// Set up a counter to pull from melody[] and beats[]
for (int i=0; i<MAX_COUNT2; i++) {
tone1 = dyingm[i];
beat = beats2[i];
duration = beat * tempo; // Set up timing
playtone1();
// A pause between notes…
delayMicroseconds(pause);
//noTone(speakerOut);
}
}
void happy() {
// Set up a counter to pull from melody[] and beats[]
for (int i=0; i<MAX_COUNT3; i++) {
tone1 = happym[i];
beat = beats3[i];
duration = beat * tempo; // Set up timing
playtone1();
// A pause between notes…
delayMicroseconds(pause);
//noTone(speakerOut);
}
}
void sad() {
// Set up a counter to pull from melody[] and beats[]
for (int i=0; i<MAX_COUNT4; i++) {
tone1 = sadm[i];
beat = beats4[i];
duration = beat * tempo; // Set up timing
playtone1();
// A pause between notes…
delayMicroseconds(pause);
//noTone(speakerOut);
}
}
void yes() {
// Set up a counter to pull from melody[] and beats[]
for (int i=0; i<MAX_COUNT5; i++) {
tone1 = yesm[i];
beat = beats5[i];
duration = beat * tempo; // Set up timing
playtone1();
// A pause between notes…
delayMicroseconds(pause);
//noTone(speakerOut);
}
}
void no() {
// Set up a counter to pull from melody[] and beats[]
for (int i=0; i<MAX_COUNT6; i++) {
tone1 = nom[i];
beat = beats6[i];
duration = beat * tempo; // Set up timing
playtone1();
// A pause between notes…
delayMicroseconds(pause);
//noTone(speakerOut);
}
}
minho
Minho
My name is Minho. My background is Digital Art. Few years ago, one of my friend introduced me vjing, but I’m not a vj yet. hahaha From searching vj thing, I found interactive things. That’s one reason I came Art school, and being here. Last semester, I took Sparklelab. The final output made me so satisfied.







Reply