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.
Project 10: Modification
-
- Freetronics Staff
- Posts:853
- Joined:Tue Apr 09, 2013 11:19 pm
- Location:Melbourne, Australia
- Contact:
Re: Project 10: Modification
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:
Then when you're done and want to take an analog reading, you stop the tone and then take your input reading:
(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
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);
Code: Select all
noTone(A0);
pinMode(A0, INPUT);
knock = analogRead(0);
- Angus
Re: Project 10: Modification
Thanks for your help. I'll give it a go.