0

Help with arduino project?
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Help with arduino project?

by Sizukhan on Thu Oct 30, 2008 4:42 pm

hi, i was wondering if i could get some help with a project im doing using my arduino.

what im trying to do is, firstly, to make a full chromatic scale that the arduino can play through a piezo speaker. what i've done so far is i've modified the sound example on arduinos site.

heres what i have so far:

Code: Select all | TOGGLE FULL SIZE
int speakerPin = 12;

int length = 49; // the number of notes
int notes[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100};
int beats[] = { 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
int tempo = 300;

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 playNote(int note, int duration) {
  //               a1   a#1   b1    c2     c#2   d2   d#2   e2    f2    f#2   g2    g#2  a2    b2    c3
  //char names[] = { '1', '2',  '3',  'a',   '4',  'b', '5',  'c',  'd',  '6',  'e',  '6', 'f',  'g',  'h' };
  //int tones[] = { 2272, 2145, 2024, 1915, 1838, 1700, 1607, 1519, 1432, 1351, 1275, 1204, 1136, 1014, 956 };
 
  //                                                                                 =========START HERE!!!=========
  //                                                                                              v 
  //int names[] = { '1',   'b',   'c',   'e',    'f',  'g',   'h',   'i',   'j',    'k',  'l',    'm',  'n',  'o',    'p',  'q',   'r',   's',   't',    'u',  'v',  'w',  'x',  'y',  'z', 'A',   'B', 'C',  'D',  'E',  'F',  'G',  'H',   'I', 'J',  'K',    'L',  'M',  'N',  'O',  'P',  'Q',  'R',  'S',  'T',  'U',  'V',  'W',   'X',  'Y', 'Z',    '2',  '3',  '4',  '5',  '6',  '7',  '8',  '9',  ' ','!', '"', '#', '$', '%', '&', '(', ')', '*', '+', ',',  '-','.',  '/',':',  ';', '<','=',  '>','?',  '`','@',  '[', ']','^',  '_','|',  '~' };
  //             0  c      c#     d      d#      e     f      f#     g      g#      a     a#      b  |  c     c#      d     d#     e      f      f#      g     g#    a     a#    b  |  c    c#     d    d#    e     f     f#    g     g#     a    a#    b  |    c     c#    d     d#    e     f     f#    g     g#    a     a#    b   |  c     c#   d     d#    e     f     f#    g     g#    a     a#    b  |  c   c#   d    d#   e    f    f#   g    g#   a    a#   b  |  c   c#    d   d#    e    f   f#    g   g#    a   a#    b |  c   c#    d   d#    e    f   f#    g   g#    a   a#    b |  c   c#    d   d#   e   f   f#  g   g#  a   a#  b | c   c#  d   d#  e   f   f#  g   g#  a   a#  b
  //             =0=                                                                                =1=                                                                            =2=                                                                    =3=                                                                        =4=                                                                    =5=                                                         =6=                                                         =7=                                                         =8=                                                 =9=                                                   
  //             0  c      c#     d      d#      e     f      f#     g      g#      a     a#      b  |  c     c#      d     d#     e      f      f#      g     g#    a     a#    b  |  c    c#     d    d#    e     f     f#    g     g#     a    a#    b  |    c     c#    d     d#    e     f     f#    g     g#    a     a#    b   |  c     c#   d     d#    e     f     f#    g     g#    a     a#    b  |  c   c#   d    d#   e    f    f#   g    g#   a    a#   b  |  c   c#    d   d#    e    f   f#    g   g#    a   a#    b |  c   c#    d   d#    e    f   f#    g   g#    a   a#    b |  c   c#    d   d#   e   f   f#  g   g#  a   a#  b | c   c#  d   d#  e   f   f#  g   g#  a   a#  b
  int tones[] = { 30577, 28861, 27242, 25713, 24269, 22907, 21621, 20408, 19262, 18181, 17161, 16198, 15289, 14430, 13621, 12856, 12135, 11453, 10811, 10204, 9631, 9090, 8580, 8099, 7644, 7215, 6810, 6428, 6067, 5726, 5405, 5102, 4815, 4545, 4290, 4049, 3822, 3607, 3405, 3214, 3033, 2863, 2702, 2551, 2407, 2272, 2145, 2024, 1911, 1803, 1702, 1607, 1516, 1431, 1351, 1275, 1203, 1136, 1072, 1012, 955, 901, 851, 803, 758, 715, 675, 637, 601, 568, 536, 506, 477, 450, 425, 401, 379, 357, 337, 318, 310, 284, 268, 253, 238, 225, 212, 200, 189, 178, 168, 158, 150, 142, 134, 126, 119, 112, 106, 100, 94, 89, 84, 79, 75, 71, 67, 63, 59, 56, 53, 50, 47, 44, 42, 39, 37, 35, 33, 31 };
  int names[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100};
  // play the tone corresponding to the note name
  for (int i = 0; i < 100; i++) {
    if (names[i] == note) {
      playTone(tones[i], duration);
    }
  }
}

void setup() {
  pinMode(speakerPin, OUTPUT);
}

void loop()
{
  playNote(notes[0], 500);
}


a little messy, yes, but it works (kind of). so what i've done is i used this page to find the specific frequency in hertz for each pitch. i then took those numbers and ran them through the formula in the example from arduino.cc:

The calculation of the tones is made following the mathematical operation:

timeHigh = period / 2 = 1 / (2 * toneFrequency)


the resulting values are the ones found in the tones[] array. now heres the problem: most of the pitches dont work. what i mean by that is that when i try to play them, something goes wrong (a number of different things may occur). for the lower pitches (notes 1-19 [elements 0-18 in the array]) play the right pitch (i THINK; they pitches are so low its hard to tell if they're right) but then they play forever. its like the sketch gets stuck; it doesnt have a chance to restart the loop. so, if you were to try to play the first pitch:

Code: Select all | TOGGLE FULL SIZE
void loop()
{
playNote(notes[0], 500);
}


it wouldnt loop every 500 ms; it would just play constantly. to prove this, if you were to put something after that line, say:

Code: Select all | TOGGLE FULL SIZE
void loop()
{
playNote(notes[0], 500);
playNote(notes[1], 500);
}


it would never play notes[1]; it would just constantly play notes[0].


another problem that occurs (with most of the higher notes) is that it plays the right pitch for about 1/4 of a second then immediately plays another pitch. sometimes it plays ONE incorrect pitch (after the quick correct pitch) and sometimes it plays multiple incorrect pitches (even if theres only ne pitch specified). so take, for example:

Code: Select all | TOGGLE FULL SIZE
void loop()
{
playNote(notes[50], 500);
}


you'll hear the right pitch first, but then about 1/4 second after the sketch starts, it goes to an incorrect pitch.


THERE ARE, however, pitches that do work. specifically pitches 19-43 (elements 18-42). those pitches play and loop fine. so i can go through a chromatic scale using just those pitches, but nothing above or below works.

so what im wondering is why the other pitches dont work and how i can fix it so they do.

thanks a ton for your help!
Sizukhan
 
Posts: 8
Joined: Thu Oct 30, 2008 4:15 pm

Re: Help with arduino project?

by westfw on Thu Oct 30, 2008 6:31 pm

To start with, I think your tones[] array needs to be unsigned ints. In your loop, you do
Code: Select all | TOGGLE FULL SIZE
i += tone*2
and with values of tone like 30577, 2*tone will end up being a negative number instead of a big number. Or you might get away with something like:
Code: Select all | TOGGLE FULL SIZE
i += 2L * (long)tone;
This probably explains the extra long durations, except I'd expect it to start working around note 14 (tone == 14430), when 2*tone is less than 32768...
westfw
 
Posts: 1582
Joined: Fri Apr 27, 2007 1:01 pm
Location: SF Bay area

Re: Help with arduino project?

by Sizukhan on Fri Oct 31, 2008 3:48 am

sorry, could you be a little more specific? im not particularly good at coding --just good enough to get by.
Sizukhan
 
Posts: 8
Joined: Thu Oct 30, 2008 4:15 pm

Re: Help with arduino project?

by westfw on Fri Oct 31, 2008 4:34 am

On arduino, an int is 16bits long, and can only hold values from -32768 to 32767. If you try to make 30000*2 fit in an int, rather than 60000 as you might expect, you get -5536. This will lead to "odd" results.

The easiest fix is probably to rewite playtone to explicitly "expand" the tone to a long, which is 32bits and can hold values up to about +/-2000000000...

Code: Select all | TOGGLE FULL SIZE
void playTone(int shorttone, int duration) {
  long tone = shorttone;
  for (long i = 0; i < duration * 1000L; i += tone * 2) {
    digitalWrite(speakerPin, HIGH);
    delayMicroseconds(tone);
    digitalWrite(speakerPin, LOW);
    delayMicroseconds(tone);
  }
}
westfw
 
Posts: 1582
Joined: Fri Apr 27, 2007 1:01 pm
Location: SF Bay area

Re: Help with arduino project?

by Sizukhan on Fri Oct 31, 2008 1:14 pm

okay, well that kind of worked. the lower pitches (from 0-19) can now be looped rather than just playing the pitch forever. however, 0-10 dont play the correct tones still and the duration for those act weird. so if you have:

Code: Select all | TOGGLE FULL SIZE
void loop()
{
playNote(notes[0], 500);
}


for example, the pitch will not play for 500 ms; it will play for maybe 250 ms (estimating). and as you get higher (1, 2, 3, ...10), the duration gets shorter and shorter. also, the pitch does get higher, but they are still not the right pitches.

also, notes past element 41 still are having the same problems as before (playing the correct note first then quickly changing to one or more incorrect notes). now another thing i dont understand is why the pitches from the example code dont work.

note frequency period timeHigh
c 261 Hz 3830 1915
d 294 Hz 3400 1700
e 329 Hz 3038 1519
f 349 Hz 2864 1432
g 392 Hz 2550 1275
a 440 Hz 2272 1136
b 493 Hz 2028 1014
C 523 Hz 1912 956


those guys. while my values are off by a little, that shouldnt be a problem. the first thing i tested with this code was how much leeway i had value-wise. so, for example, i would put in 1910 in stead of 1915, and it would still work. so i dunno why those pitches dont work... could it have something to do with int names[] array? i mean, ideally what i'd like to have is a string array so that instead of using numbers to correspond to the pitches, i could have the note names (c4, d4, e4, f#4, ect.). you can see that i kind of did that though in the commented line above int tones[].

also, im more worried about the mid/higher pitches than i am about the lower pitches, so f we cant get the low ones to work correctly, i wont be too crushed :P
Sizukhan
 
Posts: 8
Joined: Thu Oct 30, 2008 4:15 pm

Re: Help with arduino project?

by mtbf0 on Fri Oct 31, 2008 3:52 pm

first of all i notice that your high time numbers differ from the numbers used in the code you're using. why not let the compiler compute those values for you. saves time. no copying errors. no penalty at run time.

secondly c has a thing called enum, that can be used to define symbol names. in the code below C3 is 0, D3 is 1, E3 is 2, etc. corresponding to the positions of the notes in the tones array.

Code: Select all | TOGGLE FULL SIZE
#define high_time(freq) ((long)10000000 / ((long)freq * (long)2 + (long)5) / (long)10

enum NOTE_NAMES = {C3, D3, E3, F3, G3, A4, B4};

unsigned int tones[] = {
  high_time (261),                    // middle c
  high_time (294),
  high_time (329),
  high_time (349),
  high_time (392),
  high_time (440),                    // a above middle c
  high_time (493),
  high_time (523) };


so, to play middle c for half a second, you'd want

Code: Select all | TOGGLE FULL SIZE
  play_note (C3, 500);


then you should declare tones as an array of unsigned int and declare the counter in your for loop as an unsigned int. so playTone will look like

Code: Select all | TOGGLE FULL SIZE
void playTone(unsigned int tone, int duration) {
  for (unsigned int i = 0; i < duration * 1000; i += tone * 2) {
    digitalWrite(speakerPin, HIGH);
    delayMicroseconds(tone);
    digitalWrite(speakerPin, LOW);
    delayMicroseconds(tone);
  }
}


finally, for the naked self promotion portion of our program, i suggest you search this forum for orgOnan, which does pretty much what you're trying for here but with sine wave rather than square wave output, and the "rgb brain machinuino," which although, (by design), not terribly tuneful is essentially a two note polyphonic version of the orgOnan with flashing lights.
"i want to lead a dissipate existence, play scratchy records and enjoy my decline" - iggy pop, i need more
User avatar
mtbf0
 
Posts: 1645
Joined: Sat Nov 10, 2007 12:59 am
Location: oakland ca

Re: Help with arduino project?

by Sizukhan on Sat Nov 01, 2008 4:11 pm

Code: Select all | TOGGLE FULL SIZE
#define high_time(freq) ((long)10000000 / ((long)freq * (long)2 + (long)5) / (long)10

enum NOTE_NAMES = {C3, D3, E3, F3, G3, A4, B4};

unsigned int tones[] = {
  high_time (261),                    // middle c
  high_time (294),
  high_time (329),
  high_time (349),
  high_time (392),
  high_time (440),                    // a above middle c
  high_time (493),
  high_time (523) };



where does that bit of code go? and also, is this taking place of anything (methods or otherwise) in the code i have already, or is it just additional?
Sizukhan
 
Posts: 8
Joined: Thu Oct 30, 2008 4:15 pm

Re: Help with arduino project?

by Sizukhan on Sat Nov 01, 2008 8:26 pm

okay, well i managed to get it to work. i think i was making it too complicated. so here's the final code:

Code: Select all | TOGGLE FULL SIZE
int speakerPin = 12;

int length = 110; // the number of notes
char notes[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789 "; // a space represents a rest
float beats[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
                 
int tempo = 500;

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 playNote(char note, int duration) {
  //           =1=  c    c#    d     d#    e     f     f#    g     g#    a     a#    b =2= c     c#    d     d#    e     f     f#    g     g#    a     a#    b =3= c     c#    d     d#    e     f     f#    g     g#    a     a#    b =4= c    c#   d    d#   e    f    f#   g    g#   a    a#   b=5= c   c#    d    d#   e    f    f#   g    g#   a    a#   b=6= c
  char names[] = { 'a', 'b',  'c',  'd',  'e',  'f',  'g',  'h',  'i',  'j',  'k',  'l',  'm',  'n',  'o',  'p',  'q',  'r',  's',  't',  'u',  'v',  'w',  'x',  'y',  'z',  'A',  'B',  'C',  'D',  'E',  'F',  'G',  'H',  'I',  'J',  'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
  int tones[] = { 7644, 7215, 6810, 6428, 6067, 5726, 5405, 5102, 4815, 4545, 4290, 4049, 3822, 3607, 3405, 3214, 3033, 2863, 2702, 2551, 2407, 2272, 2145, 2024, 1915, 1803, 1700, 1607, 1519, 1432, 1351, 1275, 1203, 1136, 1072, 1014, 956, 901, 851, 803, 758, 715, 675, 637, 601, 568, 536, 506, 477, 450, 425, 401, 379, 357, 337, 318, 310, 284, 268, 253, 238 };
  // play the tone corresponding to the note name
  for (int i = 0; i < 61; i++) {
    if (names[i] == note) {
      playTone(tones[i], duration);
    }
  }
}

void setup() {
  pinMode(speakerPin, OUTPUT);
}

void loop() {
 
  for (int i = 0; i < length; i++)
  {
    if (notes[i] == ' ') {
      delay(beats[i] * tempo); // rest
    } else {
      playNote(notes[i], 500);
    }
  }
}



so now that i have THAT done, i was wondering if you could help me with some infrared trouble im running into with this. what im ultimately trying to do is to make a glove with switches in each finger. when you press a button, a note plays from the arduino. however, since you only have 5 fingers, you can only play 5 notes. so in order to compensate for that, i want to make it so that when you move the glove up or down, the notes you are able to play change. so say you have the glove down low to the ground, you can play notes C1-E1 (5 pitches for the five fingers). then when you move the glove up slightly, you can play notes F1-A1, and so on. so you are able to play the full scale using a combination of the five finger buttons and adjusting the height of the glove from the ground.

so what i need help with is being able to use the IR lights to give me some kind of ranged value. i'll use this value to tell the sketch what notes are available for the 5 buttons. so say for example, the glove was as low as it could go --the value would be 0 and that would tell the sketch the buttons correspond to C1-E1. say the next step up would be when the value reaches 10 --it can play F1-A1, etc.

i have the IR (LED) lights, and i've tested them a little, but im not getting the right readings. it may be a number of things --i dont have things plugged in correctly, my code is wrong, etc. so any help with this would be greatly appreciated!
Sizukhan
 
Posts: 8
Joined: Thu Oct 30, 2008 4:15 pm

Re: Help with arduino project?

by mtbf0 on Sat Nov 01, 2008 10:38 pm

i don't really see the ir working. perhaps i lack imagination.

might i suggest a sort of chording keyboard rather than a glove. with four switches, i (index), m (middle), r (ring) and p (pinkie), you enter up to 16 states. that's enough for a twelve tone scale, plus note off, plus three other signals. encoding could be something like

Code: Select all | TOGGLE FULL SIZE
---- = 0000 =  0 = note off
---p = 0001 =  1 = C
--r- = 0010 =  2 = C#
--rp = 0011 =  3 = D
-m-- = 0100 =  4 = D#
-m-p = 0101 =  5 = E
-mr- = 0110 =  6 = F
-mrp = 0111 =  7 = F#
i--- = 1000 =  8 = G
i--p = 1001 =  9 = G#
i-r- = 1010 = 10 = A
i-rp = 1011 = 11 = A#
im-- = 1100 = 12 = B
im-p = 1101 = 13 = not assigned
imr- = 1110 = 14 = not assigned
imrp = 1111 = 15 = not assigned


a similar keypad in the other hand could select the octave. or a group of thumb buttons. or an accelerometer.

i've wanted to do a chording keyboard for years. now maybe you could do it for me.
"i want to lead a dissipate existence, play scratchy records and enjoy my decline" - iggy pop, i need more
User avatar
mtbf0
 
Posts: 1645
Joined: Sat Nov 10, 2007 12:59 am
Location: oakland ca

Re: Help with arduino project?

by Sizukhan on Sun Nov 02, 2008 3:00 am

thats a pretty good idea. but i've gotta do the glove cuz thats what i planned in my project proposal. i mean, if i could a least get the IR to pick give me a ranged number, i think i could stumble through the rest to get it to work. i mean, id probably have to do everything manually, but thats fine; as long as i can get it to work. so something like:

Code: Select all | TOGGLE FULL SIZE
int irValue;

if (irValue < 10)
{
  if (indexButton == true)
  {
    playNote(notes[0], 500);
  }
  else if (middleButton == true)
  {
    playNote(notes[1], 500);
  }
  else if (ringButton == true)
  {
    playNote(notes[2], 500);
  }
  else if (pinkieButton == true)
  {
    playNote(notes[3], 500);
  }
  else if (thumbButton == true)
  {
    playNote(notes[4], 500);
  }
}
else if (10 < irValue < 20)
{
  if (indexButton == true)
  {
    playNote(notes[5], 500);
  }
  else if (middleButton == true)
  {
    playNote(notes[6], 500);
  }
  else if (ringButton == true)
  {
    playNote(notes[7], 500);
  }
  else if (pinkieButton == true)
  {
    playNote(notes[8], 500);
  }
  else if (thumbButton == true)
  {
    playNote(notes[9], 500);
  }
}


etc, etc. something like that.
Sizukhan
 
Posts: 8
Joined: Thu Oct 30, 2008 4:15 pm

Re: Help with arduino project?

by westfw on Sun Nov 02, 2008 4:28 am

Huh. I could swear I posted this already, but it didn't show up. Probably I hit a wrong button and only previewed it. Since you have things working anyway, I'll leave out the extra comments, but here's my simplified, instrumented, and commented form of your code. It seems to work as well as might be expected, using a headphone speaker with some current limiting resistors:

Code: Select all | TOGGLE FULL SIZE
int speakerPin = 12;

void playTone(int inttone, int duration) {
  long tone = (long)inttone;
  for (long i = 0; i < duration * 1000L; i += tone * 2) {
    digitalWrite(speakerPin, HIGH);
    delayMicroseconds(inttone);
    digitalWrite(speakerPin, LOW);
    delayMicroseconds(inttone);
  }
}

unsigned int tones[] = {
 /* tones to low for delayMicroseonds.  From documentation:
  *      Currently, the largest value that will produce an accurate delay is 16383.
  *
  30577, 28861, 27242, 25713, 24269, 22907, 21621, 20408, 19262, 18181, 17161,
  */
  16198, 15289, 14430,
  13621, 12856, 12135, 11453, 10811, 10204, 9631, 9090, 8580, 8099, 7644, 7215, 6810, 6428, 6067,
  5726, 5405, 5102, 4815, 4545, 4290, 4049, 3822, 3607, 3405, 3214, 3033, 2863, 2702, 2551, 2407,
  2272, 2145, 2024, 1911, 1803, 1702, 1607, 1516, 1431, 1351, 1275, 1203, 1136, 1072, 1012, 955,
  901, 851, 803, 758, 715, 675, 637, 601, 568, 536, 506, 477, 450, 425, 401, 379, 357, 337, 318,
  310, 284, 268, 253, 238, 225, 212, 200, 189, 178, 168, 158, 150, 142, 134, 126, 119, 112, 106,
 /* Painfully high notes !
  100, 94, 89, 84, 79, 75, 71, 67, 63, 59, 56, 53, 50, 47, 44, 42, 39, 37, 35, 33, 31
 */
 };

void setup() {
  pinMode(speakerPin, OUTPUT);
  pinMode(13, OUTPUT);
  Serial.begin(9600);
}

void loop()
{
  int i;

  for (i=0; i <  10; i++) {  // blink light while we wait for serial monitor to get turned on
     delay(200);
     digitalWrite(13, 1);
     delay(200);
     digitalWrite(13,0);
  }
  Serial.print("Tone generater debug.  Total tones=");
  Serial.println(sizeof(tones)/sizeof(int));
  for (i = 0; i < sizeof(tones)/sizeof(int); i++) {
    Serial.print("i=");
    Serial.print(i);
    Serial.print(", tone=");
    Serial.println(tones[i]);
    playTone(tones[i], 300);
    delay(100);
  }
}
westfw
 
Posts: 1582
Joined: Fri Apr 27, 2007 1:01 pm
Location: SF Bay area

Re: Help with arduino project?

by mtbf0 on Sun Nov 02, 2008 9:48 am

Sizukhan wrote:thats a pretty good idea. but i've gotta do the glove cuz thats what i planned in my project proposal.

think of a glove with a big lump in the palm.

or use some kind of resistive flex sensor through a schmitt trigger device like a 74ls14.

Sizukhan wrote: i mean, if i could a least get the IR to pick give me a ranged number, i think i could stumble through the rest to get it to work.

you don't say what sort of ir sensor you're intending to use. is it one of those sharp sensors that actually measure the angle of the reflected light? something else? homebrew?

anyway, here's the problem i see with an irdistance center. your hand will have to remain perfectly parallel to the floor or else you'll either get no reflection or you'll be measuring the hypoteneuse of a triangle rather than it's vertical leg.

also, if you're using one of the sharp GPDwhatevers their response is not linear. if you're doing something relying on the intensity of a reflection, (this would require a white floor and control of the ambient lighting) that's not going to be linear either.

sounds like fun, though.
"i want to lead a dissipate existence, play scratchy records and enjoy my decline" - iggy pop, i need more
User avatar
mtbf0
 
Posts: 1645
Joined: Sat Nov 10, 2007 12:59 am
Location: oakland ca

Re: Help with arduino project?

by Sizukhan on Sun Nov 02, 2008 2:27 pm

well the way i envision it is i have one LED (sender or receiver) on the bottom of the glove, and the other on the ground facing up. also, the buttons in the glove, as well as the IR LEDs will be connected to the arduino via long wires so that i dont have to have the arduino attatched to the glove or anything. now heres a question --does IR only go in a straight line, or is it more like a cone? anf if its a straight line, how do TV remotes work? because you dont have to point them in a straight line at the receiver on the TV; you just have to point in the general direction.

also, heres the kind of IR lights im using.
Sizukhan
 
Posts: 8
Joined: Thu Oct 30, 2008 4:15 pm

Re: Help with arduino project?

by mtbf0 on Sun Nov 02, 2008 4:47 pm

seems like time to wire something up and sit in the dark and see what you get off the phototransistor. you should be able to get a decent idea of the how far off center you can be and still have some illumination.
"i want to lead a dissipate existence, play scratchy records and enjoy my decline" - iggy pop, i need more
User avatar
mtbf0
 
Posts: 1645
Joined: Sat Nov 10, 2007 12:59 am
Location: oakland ca

Re: Help with arduino project?

by Sizukhan on Sun Nov 02, 2008 4:51 pm

well the problem is that i dont know how to set it up and code it.

this is what i had:

Code: Select all | TOGGLE FULL SIZE
int analogPin = 3;     // potentiometer wiper (middle terminal) connected to analog pin 3
                       // outside leads to ground and +5V

int val = 0;           // variable to store the value read



void setup()

{
 
  Serial.begin(9600);          //  setup serial

}



void loop()

{
 
  val = analogRead(analogPin);    // read the input pin
 
  Serial.println(val);             // debug value

}
Sizukhan
 
Posts: 8
Joined: Thu Oct 30, 2008 4:15 pm

Please be positive and constructive with your questions and comments.