Click here to Skip to main content
15,887,746 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
Generalfriend: frequency to MIDI should be easy right? Pin
raddevus15-Oct-18 8:57
mvaraddevus15-Oct-18 8:57 
GeneralRe: friend: frequency to MIDI should be easy right? Pin
Rick York15-Oct-18 9:35
mveRick York15-Oct-18 9:35 
GeneralRe: friend: frequency to MIDI should be easy right? Pin
raddevus15-Oct-18 9:42
mvaraddevus15-Oct-18 9:42 
GeneralRe: friend: frequency to MIDI should be easy right? Pin
Rick York15-Oct-18 10:17
mveRick York15-Oct-18 10:17 
GeneralRe: friend: frequency to MIDI should be easy right? Pin
msk471115-Oct-18 22:50
msk471115-Oct-18 22:50 
GeneralRe: friend: frequency to MIDI should be easy right? Pin
raddevus16-Oct-18 2:08
mvaraddevus16-Oct-18 2:08 
GeneralRe: friend: frequency to MIDI should be easy right? Pin
Bernhard Hiller16-Oct-18 22:52
Bernhard Hiller16-Oct-18 22:52 
GeneralRe: friend: frequency to MIDI should be easy right? Pin
Marc Clifton16-Oct-18 1:24
mvaMarc Clifton16-Oct-18 1:24 
It seems to me it's filtering out noise. 32 samples = 2^5, so the code might be easier understood if it read like:
long sum = 0;
int noisybits = 5;
for(int i=0; i<2^noisybits; i++)
{
    sum += analogRead(pinAdc);
}

sum >>= noisybits;

raddevus wrote:
the value of the sum variable will always be 0 or perfectly divisible by 32.


The value of the sum variable will not be perfectly divisible by 32, either before or after the shift. Now, if you did this:

sum = (sum >> 5) << 5;

then yes.
Latest Article - A Concise Overview of Threads

Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny

Artificial intelligence is the only remedy for natural stupidity. - CDP1802

GeneralRe: friend: frequency to MIDI should be easy right? Pin
raddevus16-Oct-18 2:12
mvaraddevus16-Oct-18 2:12 
GeneralRe: friend: frequency to MIDI should be easy right? Pin
Storm-blade16-Oct-18 1:30
professionalStorm-blade16-Oct-18 1:30 
GeneralRe: friend: frequency to MIDI should be easy right? Pin
raddevus16-Oct-18 2:13
mvaraddevus16-Oct-18 2:13 
GeneralRe: friend: frequency to MIDI should be easy right? Pin
Rick York16-Oct-18 5:32
mveRick York16-Oct-18 5:32 
GeneralRe: friend: frequency to MIDI should be easy right? Pin
raddevus16-Oct-18 8:35
mvaraddevus16-Oct-18 8:35 
GeneralRe: friend: frequency to MIDI should be easy right? Pin
Rick York16-Oct-18 9:38
mveRick York16-Oct-18 9:38 
GeneralRe: friend: frequency to MIDI should be easy right? Pin
Jan Holst Jensen218-Oct-18 1:14
Jan Holst Jensen218-Oct-18 1:14 
GeneralRe: friend: frequency to MIDI should be easy right? Pin
StatementTerminator18-Oct-18 4:19
StatementTerminator18-Oct-18 4:19 
GeneralRe: friend: frequency to MIDI should be easy right? Pin
raddevus18-Oct-18 12:47
mvaraddevus18-Oct-18 12:47 
GeneralRe: friend: frequency to MIDI should be easy right? Pin
StatementTerminator19-Oct-18 5:07
StatementTerminator19-Oct-18 5:07 
GeneralRe: friend: frequency to MIDI should be easy right? Pin
raddevus19-Oct-18 8:35
mvaraddevus19-Oct-18 8:35 
GeneralRe: friend: frequency to MIDI should be easy right? Pin
StatementTerminator19-Oct-18 8:38
StatementTerminator19-Oct-18 8:38 
GeneralRe: friend: frequency to MIDI should be easy right? Pin
raddevus19-Oct-18 8:43
mvaraddevus19-Oct-18 8:43 
GeneralRe: friend: frequency to MIDI should be easy right? Pin
englebart18-Oct-18 9:31
professionalenglebart18-Oct-18 9:31 
GeneralRe: friend: frequency to MIDI should be easy right? Pin
raddevus18-Oct-18 12:49
mvaraddevus18-Oct-18 12:49 
RantHideous Colors in Git Bash Shell Pin
David A. Gray3-Sep-18 20:52
David A. Gray3-Sep-18 20:52 
GeneralRe: Hideous Colors in Git Bash Shell Pin
Jörgen Andersson3-Sep-18 21:17
professionalJörgen Andersson3-Sep-18 21:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.