Project 10: Modification

The Experimenters Kit includes an "Eleven" Arduino-compatible board, plus a range of parts and a guide to make it easy to get started with Arduino projects. [Product Page]
Post Reply
charlest
Posts: 73
Joined: Sat Jul 27, 2013 6:08 pm

Project 10: Modification

Post by charlest » Thu Aug 01, 2013 7:09 pm

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.

angusgr
Freetronics Staff
Freetronics Staff
Posts: 853
Joined: Tue Apr 09, 2013 11:19 pm
Location: Melbourne, Australia
Contact:

Re: Project 10: Modification

Post by angusgr » Thu Aug 01, 2013 11:36 pm

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

noTone(A0);
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

charlest
Posts: 73
Joined: Sat Jul 27, 2013 6:08 pm

Re: Project 10: Modification

Post by charlest » Fri Aug 02, 2013 8:11 pm

Thanks for your help. I'll give it a go.

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests