non-defined frequency variable in first Piezo demonstration code

12 views
Skip to first unread message

Vernon Roberts

unread,
Apr 14, 2025, 11:43:50 PMApr 14
to Mozzi-users
I have looked at the code and there is no definition of frequency.
I can add a line of int frequency =440.
Then I compile, but get a constant 440 on the serial printout.
The raw value prints out perfectly.
Is there a line or two of code missing?
All the previous example work.

Mozzi-users

unread,
Apr 15, 2025, 2:03:25 AMApr 15
to Mozzi-users
Hi Vernon,
you're right, it looks like a line is missing.  

Try something like this after piezo_value has been defined:
int frequency = piezo_value / 2;
or :
int frequency = (int)(piezo_value* 0.3f);
The multiply by a float --might-- work faster than divides.

Does that give a result in a range you can hear?  Let us know what works for you...

Thanks for noticing the missing line!

Tim

Vernon Roberts

unread,
Apr 15, 2025, 9:17:08 PMApr 15
to mozzi...@googlegroups.com
The solution worked perfectly

Thanks,
Vern



Sent via the Samsung Galaxy S23 Ultra 5G, an AT&T 5G smartphone
--
You received this message because you are subscribed to a topic in the Google Groups "Mozzi-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mozzi-users/PHTqHuMQcaU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mozzi-users...@googlegroups.com.
To view this discussion, visit https://groups.google.com/d/msgid/mozzi-users/f759ce0a-90c1-4931-80ff-6a889ceed5ffn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages