Page 1 of 1

Project 10: Modification

Posted: Thu Aug 01, 2013 7:09 pm
by charlest
Hi, thanks for making this kit available.

I've just completed Project 10: Detecting Vibration & Knocks.

I was wondering whether it would be possible to include the availability to make sounds together with detecting knocks? FYI, the piezo module is already connected to analogue input pin A0.

Re: Project 10: Modification

Posted: Thu Aug 01, 2013 11:36 pm
by angusgr
Yes, you can do this you just can't do both at the same time.

So to switch the piezo on pin A0 to an output and play a 440Hz tone:

Code: Select all

pinMode(A0, OUTPUT);
tone(A0, 440);
Then when you're done and want to take an analog reading, you stop the tone and then take your input reading:

Code: Select all

pinMode(A0, INPUT);
knock = analogRead(0);
(Note that you'll need something in between these two code snippets in order for the Eleven to pause and actually allow some time to play the tone. 'delay(1000);' will pause it for a second.

- Angus

Re: Project 10: Modification

Posted: Fri Aug 02, 2013 8:11 pm
by charlest
Thanks for your help. I'll give it a go.