Hardware Reference
In-Depth Information
Listing 9-16 compares the relative intervals of the knocks, not the absolute time between them. So, for example,
the door should open regardless of whether you carry out the pulsing pattern slowly or quickly, as long as the pattern
is correct. This makes the timing less tricky, which, while making it less secure, can also make the box less picky about
your tempo, which may be slightly off.
Listing 9-16. Code Comparing the Intervals of Knocks
int totaltimeDifferences=0;
int timeDiff=0;
for (i=0;i<MAX_KNOCKS;i++){ // Normalize the times
knockReadings[i]= map(knockReadings[i],0, maxKnockInterval, 0, 100);
timeDiff = abs(knockReadings[i]-secretCode[i]);
if (timeDiff > rejectValue){ // Individual value too far out of whack
return false;
}
totaltimeDifferences += timeDiff;
}
// It can also fail if the whole thing is too inaccurate.
if (totaltimeDifferences/secretKnockCount>averageRejectValue){
return false;
}
return true;
}
The code in Listing 9-16 uses the knock reading array to hold the pattern of knock pauses.
Summary
Transitioning from standard Arduino to a professional approach is a big step. Knowing how to use a high-speed,
32-bit, and feature-rich MCU is critical in moving toward creating high-end projects for video, audio, and peer-to-peer
communication. Additionally, working with the low-end Atmel chips cuts costs and allows you to work on projects with
multiple small parts. For example, you can create a set of Arduinos, using the ATtiny85, that blinks a single code per
block. It is much cheaper to use the ATtiny85, and the form factor is small enough to keep the project relatively small.
 
Search WWH ::




Custom Search