| |
PHYSICAL COMPUTING
Projects
[Blink] [Runway] [Move] [Pixel Bend]
Project 2: Runway
Description
This project consists in developing a wearable device which
can determine and measure the different signals either
analogical or digital by interacting with the external
environment. For my project, I decided to create a sound
generator implemented in a bracelet.
The materials needed for this projects are the following:
- 1 Arduino module
- 1 Sharp GPD2D12 IR ranger
- 1 Solderless breadboard
- 1 Bracelet
- 1 Speaker
- 6 LED's
- 6 resistors
The schematic diagram for this project is the following
Figure 1
Procedure
This project shows us the way how the distance between the
sensor (located under the hand) and the surface of the table is
used for generating sound and turning leds on or off, depending
on how far or near is your hand.
Figure 2
Figure 3
Code
int speakerPin = 9;
int i, irReader = 1; // the analog input pin for the ir
reader
int pins[] = { 2, 4, 7, 8, 12, 13 }; // an array of pin numbers
void playTone(int tone, int duration) {
for (long i = 0; i < duration * 1000L; i += tone * 2) {
digitalWrite(speakerPin, HIGH);
delayMicroseconds(tone);
digitalWrite(speakerPin, LOW);
delayMicroseconds(tone);
}
}
void setup() {
pinMode(speakerPin, OUTPUT);
for (i = 0; i < 6; i++) // the array elements are numbered
from 0 to num_pins - 1
pinMode(pins[i], OUTPUT); // set each pin as an output
}
void loop() {
i = analogRead(irReader);
if(i > 0 && i < 112){
digitalWrite(pins[0], HIGH);
playTone (1915, 300);
}
else{
digitalWrite(pins[0], LOW);
digitalWrite(pins[1], LOW);
digitalWrite(pins[2], LOW);
digitalWrite(pins[3], LOW);
digitalWrite(pins[4], LOW);
digitalWrite(pins[5], LOW);
}
if(i > 112 && i < 224){
digitalWrite(pins[0], HIGH);
digitalWrite(pins[1], HIGH);
playTone (1700, 300);
}
else{
digitalWrite(pins[1], LOW);
digitalWrite(pins[2], LOW);
digitalWrite(pins[3], LOW);
digitalWrite(pins[4], LOW);
digitalWrite(pins[5], LOW);
}
if(i > 224 && i < 336){
digitalWrite(pins[0], HIGH);
digitalWrite(pins[1], HIGH);
digitalWrite(pins[2], HIGH);
playTone (1519, 300);
}
else{
digitalWrite(pins[2], LOW);
digitalWrite(pins[3], LOW);
digitalWrite(pins[4], LOW);
digitalWrite(pins[5], LOW);
}
if(i > 336 && i < 448){
digitalWrite(pins[0], HIGH);
digitalWrite(pins[1], HIGH);
digitalWrite(pins[2], HIGH);
digitalWrite(pins[3], HIGH);
playTone (1432, 300);
}
else{
digitalWrite(pins[3], LOW);
digitalWrite(pins[4], LOW);
digitalWrite(pins[5], LOW);
}
if(i > 448 && i < 560){
digitalWrite(pins[0], HIGH);
digitalWrite(pins[1], HIGH);
digitalWrite(pins[2], HIGH);
digitalWrite(pins[3], HIGH);
digitalWrite(pins[4], HIGH);
playTone (1275, 300);
}
else{
digitalWrite(pins[4], LOW);
digitalWrite(pins[5], LOW);
}
if(i > 560 && i < 672){
digitalWrite(pins[0], HIGH);
digitalWrite(pins[1], HIGH);
digitalWrite(pins[2], HIGH);
digitalWrite(pins[3], HIGH);
digitalWrite(pins[4], HIGH);
digitalWrite(pins[5], HIGH);
playTone (1136, 300);
}
else{
digitalWrite(pins[5], LOW);
}
}
|
|