An Interactive Painting

 

I was always interested into a classical paintings and old medium still offers to me but to people, in general, especially if I would be able to make a step forward and from the classical paintings make an interactive people that may communicate with viewers even more than it does. Baroque paintings use effects that people around the painting have had the feeling that the eyes follow them whenever they go in a room. This eyes made me wonder what is possible with “simple” paintings and object because if anyone would have interested about what is going on behind, even the following idea is simple and great.

 

Since I came to Canada to Montreal it is my first experience in Americas and everything is very new to me so I would like to do series of paintings that would express my experience in this massive city and country. When I was thinking about the painting and what I can do to interested a viewer and myself. The sound was the most suitable for me because it is not that obvious and offensive like a video… or maybe light. I would like to keep a sentimental feeling of the magical classical paintings.

 

I miss Prague dearly, I miss Glasgow even more, but now I am in Montreal. In the huge city and the even bigger country full of forests; however, I can’t hear any animals here. Not even seagulls when I go for a run. Are separate from nature and we don’t want to be in connection with nature anymore. We are a tourist in nature and animals are just visitors in a city. Here in Montreal. Are you all covering ourselves in a shelf that protects us from a busyness of the city and we are already scared of the pure nature because everything must have perfect order and nature doesn’t fit into this order. With the sound, I would like to bring and show this scariness of the city with ambient sound when slowly come to the painting and since you would come further up the volume slightly turns up with the more specific sound and you would be able to hear and see more details in the painting. This is the reason why I would like to use a concrete with electronics and details stuff. The reason why I would like to create an abstract piece that is because my feeling, here, in Montreal, are not specific and I am still not sure how do I feel about this place, so I don’t want to be too much specific.

 

I recorded a couple of sounds that are specific for my staying here such as walking to school, running and metro transportations. Each place is slightly different. When I played with the sound I realized that when I slow the sound it has completely raw simple melody, from the roots and this is what I like. Time here flies quiver, but sometimes I have a feeling it is a very long period of time and over this time it might happen anything back in the home.

 

PROCESS

 


 

Honestly, I expected something completely different from my final painting but I guess it is better to start with a quite unrealistic idea and achieved, at least, half of the idea rather than starting with a small one…

Research


https://vimeo.com/104811430

http://www.slideshare.net/ashifar/transparent-concrete?related=1

http://ramshackblog.blogspot.ca/2012/02/ultrasonic-range-finder-using-sdm-io.html

http://www.philipbeesleyarchitect.com/

http://litracon.hu/en

 

http://www.paulferragut.com/wp-content/uploads/2011/04/IMG_20110227_143610-e1303766003161.jpg

http://entertainment.howstuffworks.com/arts/artwork/eyes-in-painting-follow.htm

http://www.buildcircuit.com/obstacle-sensor-using-arduino-and-hcsr04/

http://slab.concordia.ca/2013/general/musical-instrument-shield/

https://learn.adafruit.com/adafruit-wave-shield-audio-shield-for-arduino/solder

http://www.roland-riegel.de/sd-reader/index.html

http://hackaday.com/2013/12/03/a-speaking-ultrasonic-distance-sensor/

For my responsive painting, I decided to go for a wave shield and distance sensors. I was not sure about which type of the distance sensor is the best for my project so I tested a couple of them. However, I had a lot troubles with a wave shield itself…. And not just because of soldering.

Actually, I tried these ones:

analog distance sensor – IR range sensor http://slab.concordia.ca/2009/arduino/ir-range-finder/

ultrasonic range sensor – the one with five pins http://slab.concordia.ca/2009/arduino/ultrasonic-range-finder/

ultrasonic distance sensor hc-sr04

PING))) Ultrasonic Distance Sensor

Finally, I decided to use ultrasonic distance sensor 04, because I found and example what was very useful for me and it was my starting point.

 

The first one I misplaced two parts so I burn them, but I tried at least how to solder all these parts together and see how difficult it was. Even though I followed the instructions I still made a mistake and I had to start over…

IMG_1793 IMG_1794 IMG_1795 IMG_1796

 

After I destroyed the first wave shield I was hoping for a better success on the second one, although I was following the instruction even more than on the first one it wasn’t that reliable how I expected, especially for the SD card I had a lot of troubles. It started to be quite a flustering  because I still was not able to move on with the code and work with the sound without any idea how it’s gonna work wasn’t the greatest thing.

An example of troubleshoots what I was having.

Screen Shot 2015-11-25 at 19.48.14 Screen Shot 2015-11-25 at 20.15.09 Screen Shot 2015-11-26 at 18.54.32   Screen Shot 2015-11-26 at 19.09.40

 

I was working at Maquette Lab on my frames because I do not like working at woodshop and after a discussion of the frames, I decided to use CNC machine because it seemed like the best way to do it and the most efficient. I though if I draw the frames in 123design it would be very simple but from very simple task appears very challenging thing that I was solving there for more than 5 hours..

I do not understand how this was possible, but I believe it is I do not well the technicians there and I have a diffrent style of working and on top that I don’t know inches that well so it a big deal here because everything is in inches…

Even though I had my maquette it still did not work. Luckily I get the frames together, only pity thing is if I wouldn’t work continuously and I decided which sensor I will use I could easily cut them on the CNC machine and I wouldn’t have to cut them after on a different machine. Well, I decided later which sensor I want to of course when I was cutting holes I destroyed one of them so I had to go buy the new one…

IMG_1808 IMG_1807 IMG_1806 IMG_1805

I tried to solve this problem and on Friday I was working in the lab very long to fix the problem and desolder some parts and solder them again or see of there is any code errors.     Screen Shot 2015-11-27 at 13.30.05 Screen Shot 2015-11-27 at 13.36.15 Screen Shot 2015-11-27 at 13.38.16  Screen Shot 2015-11-27 at 14.39.47I tried to fix this problem and I was still hoping just for the code problem; however, it was very disappointing that this was just shield problem. I tried 5 different SD cards and format them millions of time. I was still using the sound examples what I got because I haven’t had enough time to develop the code and sound yet because I was focusing more to get the shield working. In addition, on Friday I started to solder all these parts together what purchase. IMG_1809IMG_1815IMG_1816IMG_1812IMG_1810

 

Everything seemed very ok without any big issues so on Friday I got a new wave shield and over the weekend I had to work on different idea probably to make an interactive drawing with my conductive ink… Honestly, I expected that this time, we shield would work…

Screen Shot 2015-11-27 at 17.32.06 Screen Shot 2015-12-03 at 00.16.50 Screen Shot 2015-12-03 at 13.37.16 Screen Shot 2015-12-03 at 14.21.20Since I didn’t know what or where is the problem even though Elio told me they had a lot of troubles with this wave shield so they don’t use these shields anymore I still believed I would be able to use it. Since it wasn’t working I used a different idea even though it wasn’t that strong because I wanted to have something for the finals. IMG_1852 IMG_1839 IMG_1843 IMG_1842 IMG_1841

 

I used a capacitive code and bare conductive ink and very simple blink effect just to have something. I am aware that we are not supposed to touch the paintings, but this move was miserable step how to solve it al least somehow.

 

Examples, of my sound process -> since the shield did not work the whole time and I was trying couple different shields and I had problems of them again I decided to try just the wave shield. Although, I tried to keep working on the sound it was very difficult for my to find out it’s gonna sound what kind of sound I could use.

Screen Shot 2015-12-03 at 17.46.54 Screen Shot 2015-12-03 at 17.47.02 Screen Shot 2015-12-03 at 17.47.05  Screen Shot 2015-12-03 at 17.48.00 Screen Shot 2015-12-03 at 17.48.19 Screen Shot 2015-12-03 at 17.48.22

The day before of the finals, on Wednesday I solder a new wave shield and it was working for a couple of minutes but… it has an SD card error again so it was the biggest disappointment. I left the lab at 3 am with the feeling I did everything that I could, but the shield is not working.

Final soldering on Wednesday night.

IMG_1884 IMG_1883 IMG_1882 IMG_1869 IMG_1868 IMG_1867 IMG_1866 IMG_1865 IMG_1864 IMG_1862

 

When I came on Thursday suddenly it all worked… I do not understand why, but it was working which I was very glad about. I do not understand how but it is working now which I am very glad about! Even though on the finals, it wasn’t ideal…

 

Screen Shot 2015-12-03 at 18.50.50 Screen Shot 2015-12-08 at 15.12.05 Screen Shot 2015-12-08 at 15.12.07 Screen Shot 2015-12-08 at 16.15.00 Screen Shot 2015-12-08 at 16.15.01 Screen Shot 2015-12-08 at 16.15.03 Screen Shot 2015-12-08 at 17.09.46 Screen Shot 2015-12-08 at 17.22.32 Screen Shot 2015-12-08 at 17.26.11

 

I am still working on the paintings and I put there two sensors and I am trying to figure how this is working. I know this is over of the class, but I still want to make this code and painting perfect!

To conclude, over the month I spent more than 20hours of the week in the labs and workshop to create and design the painting and I am very disappointed that most of the time I was trying to fix problems what I had. I am more than I had to go through this project and tried to fixing problems and trying to write codes for different sensors. Finally, I learnt how to solder parts together and that the writing code it is actually sitting just in front of the computer but about the perfect preparation.

IMG_1885 IMG_1886 IMG_1884 IMG_1883 IMG_1882 IMG_1869

I believe I keep work on this projected future because it is still not finished how I want to be and I haven’t had enough time to create painting what I would like. Definitely, the critique was very useful and I am glad to hear these opinions. I would like to try to use real-time sounds from different places and make more coherent without the conductive painting but probably I would like to try to play with the sound and light.

Code what I used it from this website – http://hackaday.com/2013/12/03/a-speaking-ultrasonic-distance-sensor/

To conclude, it was not ideal the whole process but I was really trying to get the shield working so I am using a code what someone wrote; however, this week I modify the code and think how can i improve the idea and i could do…

If I woulnt use any example of the code I never would be able to finish at least something because I need more time and I already spent a lot of time on this project and honestly, I believe I tried my best to not giving up and keep working even though the processes was really challenging for me.

Videos of experiments


 

 

Sound


 

Arduino Codes


 

Example of distance sensor code


// Distanzmessung 10-100cm mit Sprachausgabe K.Hirschelmann 22.11.2013

#include <FatReader.h>
#include <SdReader.h>
#include <avr/pgmspace.h>
#include “WaveUtil.h”
#include “WaveHC.h”

#define trigger 7 // Arduino Pin an HC-SR04 Trig
#define echo 6 // Arduino Pin an HC-SR04 Echo

SdReader card; // This object holds the information for the card
FatVolume vol; // This holds the information for the partition on the card
FatReader root; // This holds the information for the filesystem on the card
FatReader f; // This holds the information for the file we’re play

WaveHC wave; // This is the only wave (audio) object, since we will only play one at a time

// 0-9, 10-19, 20-21
//—————————-
char * wavFiles[] = {
“10.WAV”,”15.WAV”,”20.WAV”,”25.WAV”,”30.WAV”,”35.WAV”,”40.WAV”,”45.WAV”,”50.WAV”,”55.WAV”,
“60.WAV”,”65.WAV”,”70.WAV”,”75.WAV”,”80.WAV”,”85.WAV”,”90.WAV”,”95.WAV”,”100.WAV”,”more1m.WAV”,
“less10cm.WAV”,”hello.WAV”};

////////////////////////////////////////////////////////////////
// this handy function will return the number of bytes currently
// free in RAM, great for debugging!
int freeRam(void)
{
extern int __bss_end;
extern int *__brkval;
int free_memory;
if((int)__brkval == 0) {
free_memory = ((int)&free_memory) – ((int)&__bss_end);
}
else {
free_memory = ((int)&free_memory) – ((int)__brkval);
}
return free_memory;
}

/////////////////////////////////////////////////////
void sdErrorCheck(void)
{
if (!card.errorCode()) return;
putstring(“\n\rSD I/O error: “);
Serial.print(card.errorCode(), HEX);
putstring(“, “);
Serial.println(card.errorData(), HEX);
while(1);
}

/////////////////////////////////////////////////////
void setup() {

pinMode(trigger, OUTPUT);
pinMode(echo, INPUT);

// set up serial port
Serial.begin(9600);
putstring_nl(“WaveHC”);

putstring(“Free RAM: “); // This can help with debugging, running out of RAM is bad
Serial.println(freeRam()); // if this is under 150 bytes it may spell trouble!

// Set the output pins for the DAC control. This pins are defined in the library
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);

// pin13 LED
pinMode(13, OUTPUT);

// if (!card.init(true)) { //play with 4 MHz spi if 8MHz isn’t working for you
if (!card.init()) { //play with 8 MHz spi (default faster!)
putstring_nl(“Card init. failed!”); // Something went wrong, lets print out why
sdErrorCheck();
while(1); // then ‘halt’ – do nothing!
}

// enable optimize read – some cards may timeout. Disable if you’re having problems
card.partialBlockRead(true);

// Now we will look for a FAT partition!
uint8_t part;
for (part = 0; part < 5; part++) { // we have up to 5 slots to look in
if (vol.init(card, part))
break; // we found one, lets bail
}
if (part == 5) { // if we ended up not finding one 😦
putstring_nl(“No valid FAT partition!”);
sdErrorCheck(); // Something went wrong, lets print out why
while(1); // then ‘halt’ – do nothing!
}

// Lets tell the user about what we found
putstring(“Using partition “);
Serial.print(part, DEC);
putstring(“, type is FAT”);
Serial.println(vol.fatType(),DEC); // FAT16 or FAT32?

// Try to open the root directory
if (!root.openRoot(vol)) {
putstring_nl(“Can’t open root dir!”); // Something went wrong,
while(1); // then ‘halt’ – do nothing!
}

playcomplete(wavFiles[21]); // Startmessage

// Whew! We got past the tough parts.
putstring_nl(“Ready!”);
}

long duration=0;
long distance=0;

////////////////////////////////////////////////////////////
void loop() {

digitalWrite(trigger, LOW);
delayMicroseconds(2);

digitalWrite(trigger, HIGH);
delayMicroseconds(0);

digitalWrite(trigger, LOW);
duration = pulseIn(echo, HIGH);
distance = duration / 48.2; // value 148 for distances in inch

Serial.print(“Distance “);
Serial.print(distance);
Serial.println(“cm”);

// playing if distances are more than 1Meter
if (distance>102) {
Serial.println(“more than 1m”);
playcomplete(wavFiles[19]); }

// select for playing distances between 1m and 10cm
if (distance>=97&&distance<102) {
Serial.println(“100”);
playcomplete(wavFiles[18]); }
if (distance>=92&&distance<97) {
Serial.println(“95”);
playcomplete(wavFiles[17]); }
if (distance>=87&&distance<92) {
Serial.println(“90”);
playcomplete(wavFiles[16]); }
if (distance>=82&&distance<87) {
Serial.println(“85”);
playcomplete(wavFiles[15]); }
if (distance>=77&&distance<82) {
Serial.println(“80”);
playcomplete(wavFiles[14]); }
if (distance>=72&&distance<77) {
Serial.println(“75”);
playcomplete(wavFiles[13]); }
if (distance>=67&&distance<72) {
Serial.println(“70”);
playcomplete(wavFiles[12]); }
if (distance>=62&&distance<67) {
Serial.println(“65”);
playcomplete(wavFiles[11]); }
if (distance>=57&&distance<62) {
Serial.println(“60”);
playcomplete(wavFiles[10]); }
if (distance>=52&&distance<57) {
Serial.println(“55”);
playcomplete(wavFiles[9]); }
if (distance>=47&&distance<52) {
Serial.println(“50”);
playcomplete(wavFiles[8]); }
if (distance>=42&&distance<47) {
Serial.println(“45”);
playcomplete(wavFiles[7]); }
if (distance>=37&&distance<42) {
Serial.println(“40”);
playcomplete(wavFiles[6]); }
if (distance>=32&&distance<37) {
Serial.println(“35”);
playcomplete(wavFiles[5]); }
if (distance>=27&&distance<32) {
Serial.println(“30”);
playcomplete(wavFiles[4]); }
if (distance>=22&&distance<27) {
Serial.println(“25”);
playcomplete(wavFiles[3]); }
if (distance>=17&&distance<22) {
Serial.println(“20”);
playcomplete(wavFiles[2]); }
if (distance>=12&distance<17) {
Serial.println(“15”);
playcomplete(wavFiles[1]); }
if (distance>=7&&distance<12) {
Serial.println(“10”);
playcomplete(wavFiles[0]); }

// playing if distances are less than 10cm
if (distance<7) {
Serial.println(“less than 10cm”);
playcomplete(wavFiles[20]); }

}

/////////////////////////////////////////////////////////
// Plays a full file from beginning to end with no pause.
void playcomplete(char *name) {
// call our helper to find and play this name
playfile(name);
while (wave.isplaying) {
// do nothing while its playing
}
// now its done playing
}

//////////////////////////////////////////////////////////
void playfile(char *name) {
// see if the wave object is currently doing something
if (wave.isplaying) {// already playing something, so stop it!
wave.stop(); // stop it
}
// look in the root directory and open the file
if (!f.open(root, name)) {
putstring(“Couldn’t open file “); Serial.print(name); return;
}
// OK read the file and turn it into a wave object
if (!wave.create(f)) {
putstring_nl(“Not a valid WAV”); return;
}
// ok time to play! start playback
wave.play();
}

 

Two distance sensors


 

 

#include <FatReader.h>
#include <SdReader.h>
#include <avr/pgmspace.h>
#include “WaveUtil.h”
#include “WaveHC.h”

#define trigger1 7 // Arduino Pin an HC-SR04 Trig
#define echo1 6 // Arduino Pin an HC-SR04 Echo

#define trigger2 8 // Arduino Pin an HC-SR04 Trig
#define echo2 9 // Arduino Pin an HC-SR04 Echo
SdReader card; // This object holds the information for the card
FatVolume vol; // This holds the information for the partition on the card
FatReader root; // This holds the information for the filesystem on the card
FatReader f; // This holds the information for the file we’re play

WaveHC wave; // This is the only wave (audio) object, since we will only play one at a time

// 0-9, 10-19, 20-21
//—————————-
char * wavFiles[] = {
“10.WAV”,”15.WAV”,”20.WAV”,”25.WAV”,”30.WAV”,”35.WAV”,”40.WAV”,”45.WAV”,”50.WAV”,”55.WAV”,
“60.WAV”,”65.WAV”,”70.WAV”,”75.WAV”,”80.WAV”,”85.WAV”,”90.WAV”,”95.WAV”,”100.WAV”,”more1m.WAV”,
“less10cm.WAV”,”hello.WAV”};

////////////////////////////////////////////////////////////////
// this handy function will return the number of bytes currently
// free in RAM, great for debugging!
int freeRam(void)
{
extern int __bss_end;
extern int *__brkval;
int free_memory;
if((int)__brkval == 0) {
free_memory = ((int)&free_memory) – ((int)&__bss_end);
}
else {
free_memory = ((int)&free_memory) – ((int)__brkval);
}
return free_memory;
}

/////////////////////////////////////////////////////
void sdErrorCheck(void)
{
if (!card.errorCode()) return;
putstring(“\n\rSD I/O error: “);
Serial.print(card.errorCode(), HEX);
putstring(“, “);
Serial.println(card.errorData(), HEX);
while(1);
}

/////////////////////////////////////////////////////
void setup() {

pinMode(trigger1, OUTPUT);
pinMode(echo1, INPUT);

pinMode(trigger2, OUTPUT);
pinMode(echo2, INPUT);

// set up serial port
Serial.begin(9600);
putstring_nl(“WaveHC”);

putstring(“Free RAM: “); // This can help with debugging, running out of RAM is bad
Serial.println(freeRam()); // if this is under 150 bytes it may spell trouble!

// Set the output pins for the DAC control. This pins are defined in the library
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);

// pin13 LED
pinMode(13, OUTPUT);

// if (!card.init(true)) { //play with 4 MHz spi if 8MHz isn’t working for you
if (!card.init()) { //play with 8 MHz spi (default faster!)
putstring_nl(“Card init. failed!”); // Something went wrong, lets print out why
sdErrorCheck();
while(1); // then ‘halt’ – do nothing!
}

// enable optimize read – some cards may timeout. Disable if you’re having problems
card.partialBlockRead(true);

// Now we will look for a FAT partition!
uint8_t part;
for (part = 0; part < 5; part++) { // we have up to 5 slots to look in
if (vol.init(card, part))
break; // we found one, lets bail
}
if (part == 5) { // if we ended up not finding one 😦
putstring_nl(“No valid FAT partition!”);
sdErrorCheck(); // Something went wrong, lets print out why
while(1); // then ‘halt’ – do nothing!
}

// Lets tell the user about what we found
putstring(“Using partition “);
Serial.print(part, DEC);
putstring(“, type is FAT”);
Serial.println(vol.fatType(),DEC); // FAT16 or FAT32?

// Try to open the root directory
if (!root.openRoot(vol)) {
putstring_nl(“Can’t open root dir!”); // Something went wrong,
while(1); // then ‘halt’ – do nothing!
}

playcomplete(wavFiles[21]); // Startmessage
delay(2000);

// Whew! We got past the tough parts.
putstring_nl(“Ready!”);
}

int getDistance(int t, int e) {
long duration=0;
long distance=0;
digitalWrite(t, LOW);
delayMicroseconds(2);

digitalWrite(t, HIGH);
delayMicroseconds(10);

digitalWrite(t, LOW);
duration = pulseIn(e, HIGH);

Serial.print(“Distance “);
Serial.print(distance);
Serial.println(“cm”);
return distance = duration / 48.2; // value 148 for distances in inch
}
////////////////////////////////////////////////////////////
void loop() {

// digitalWrite(trigger, LOW);
// delayMicroseconds(2);
//
// digitalWrite(trigger, HIGH);
// delayMicroseconds(10);
//
// digitalWrite(trigger, LOW);
// duration = pulseIn(echo, HIGH);
// distance = duration / 48.2; // value 148 for distances in inch
//
// Serial.print(“Distance “);
// Serial.print(distance);
// Serial.println(“cm”);
int distance1 = getDistance(trigger1, echo1);
int distance2 = getDistance(trigger2, echo2);
Serial.println (distance1);
Serial.println (distance2);

// playing if distances are more than 1Meter
if (distance1>102) {
Serial.println(“more than 1m”);
playcomplete(wavFiles[19]); }

// if (distance2>102) {
// Serial.println(“more than 1m”);
// playcomplete(wavFiles[19]); }

// select for playing distances between 1m and 10cm
if (distance1>=97 && distance1<102) {
Serial.println(“100”);
playcomplete(wavFiles[18]); }

// if (distance2>=97 && distance2<102) {
// Serial.println(“100”);
// playcomplete(wavFiles[18]); }

if (distance1>=92 && distance1<97) {
Serial.println(“95”);
playcomplete(wavFiles[17]); }
if (distance1>=87 && distance1<92) {
Serial.println(“90”);
playcomplete(wavFiles[16]); }
if (distance1>=82 && distance1<87) {
Serial.println(“85”);
playcomplete(wavFiles[15]); }
if (distance1>=77 && distance1<82) {
Serial.println(“80”);
playcomplete(wavFiles[14]); }
if (distance1>=72 && distance1<77) {
Serial.println(“75”);
playcomplete(wavFiles[13]); }
if (distance1>=67 && distance1<72) {
Serial.println(“70”);
playcomplete(wavFiles[12]); }
if (distance1>=62 && distance1<67) {
Serial.println(“65”);
playcomplete(wavFiles[11]); }
if (distance1>=57 && distance1<62) {
Serial.println(“60”);
playcomplete(wavFiles[10]); }
if (distance1>=52 && distance1<57) {
Serial.println(“55”);
playcomplete(wavFiles[9]); }
if (distance1>=47 && distance1<52) {
Serial.println(“50”);
playcomplete(wavFiles[8]); }
if (distance1>=42 && distance1<47) {
Serial.println(“45”);
playcomplete(wavFiles[7]); }
if (distance1>=37 && distance1<42) {
Serial.println(“40”);
playcomplete(wavFiles[6]); }
if (distance1>=32 && distance1<37) {
Serial.println(“35”);
playcomplete(wavFiles[5]); }
if (distance1>=27 && distance1<32) {
Serial.println(“30”);
playcomplete(wavFiles[4]); }
if (distance1>=22 && distance1<27) {
Serial.println(“25”);
playcomplete(wavFiles[3]); }
if (distance1>=17 && distance1<22) {
Serial.println(“20”);
playcomplete(wavFiles[2]); }
if (distance1>=12 && distance1<17) {
Serial.println(“15”);
playcomplete(wavFiles[1]); }
if (distance1>=7 && distance1<12) {
Serial.println(“10”);
playcomplete(wavFiles[0]); }

// playing if distances are less than 10cm
if (distance1<7) {
Serial.println(“less than 10cm”);
playcomplete(wavFiles[20]); }
delay(25);

if (distance2<7) {
Serial.println(“less than 10cm”);
playcomplete(wavFiles[20]); }
delay(25);
}

/////////////////////////////////////////////////////////
// Plays a full file from beginning to end with no pause.
void playcomplete(char *name) {
// call our helper to find and play this name
playfile(name);
while (wave.isplaying) {
// do nothing while its playing
}
// now its done playing
}

//////////////////////////////////////////////////////////
void playfile(char *name) {
// see if the wave object is currently doing something
if (wave.isplaying) {// already playing something, so stop it!
wave.stop(); // stop it
}
// look in the root directory and open the file
if (!f.open(root, name)) {
putstring(“Couldn’t open file “); Serial.print(name); return;
}
// OK read the file and turn it into a wave object
if (!wave.create(f)) {
putstring_nl(“Not a valid WAV”); return;
}
// ok time to play! start playback
wave.play();
}

 

Capacitive Sensor Code


#include <CapacitiveSensor.h>

 

CapacitiveSensor cs_4_2 = CapacitiveSensor(4,2);
CapacitiveSensor cs_4_3 = CapacitiveSensor(4,3);
CapacitiveSensor cs_4_5 = CapacitiveSensor(4,5);
int led1 = 9;
int led2 = 10;
int led3 = 11;
float previous_value1 = 0;
float previous_value2 = 0;
float previous_value3 = 2;
const int ledPin = 13;
int ledState = LOW;

unsigned long previousMillis = 0;

const long interval = 1000;
void setup()
{
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(ledPin, OUTPUT);

}

void loop()
{
long touch1 = cs_4_2.capacitiveSensor(3);
long touch2 = cs_4_3.capacitiveSensor(3);
long touch3 = cs_4_5.capacitiveSensor(100);

long value1 = touch1 * 0.4 + previous_value1 * 0.8;
previous_value1 = touch1;

long value2 = touch2 * 0.2 + previous_value2 * 0.9;
previous_value2 = touch2;

long value3 = touch3 * 0.9 + previous_value3 * 0.8;
previous_value3 = touch3;

analogWrite(led1, value1);
analogWrite(led2, value2);
analogWrite(led3, value3);

delay(10); // arbitrary delay to limit data to serial port

unsigned long currentMillis = millis();

if (currentMillis – previousMillis >= interval) {
// save the last time you blinked the LED
previousMillis = currentMillis;

// if the LED is off turn it on and vice-versa:
if (ledState == LOW) {
ledState = HIGH;
} else {
ledState = LOW;
}

// set the LED with the ledState of the variable:
digitalWrite(ledPin, ledState);
}

}

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s