User manual
LPCXpresso Experiment Kit - User’s Guide
Page 45
Copyright 2013 © Embedded Artists AB
outputs must be controlled). A fast changing signal must for example be sampled often in order not to
miss any important information.
In this experiment we shall sample the push-button with different sample rates. The forever-loop of the
previous experiment (Lab 2d) is used. A delay function is introduced before checking push-button
state. Use the delay function created in Lab 1c for this. If the delay is for example 100 ms, the effect is
that the push-button is sampled at 10 Hz rate.
// declare variables
uint8_t stateLED;
// Initialize pins to be inputs and outputs,
// set outputs to defined states
...
//enter forever loop
while (1)
{
//delay a specified period of time (the sample period)
...
//check if push-button is pressed
if (...)
{
//toggle LED
...
//wait until push-button is released
while(...);
}
}
Experiment with different delay settings / sample rates and see how fast you need the sample to push-
button in order not to miss a quick push-button press.
About what sample rate is needed in order not to miss any button presses? ____________________
As an added bonus, the problem with contact bounce is also handled when the delay was added. That
is because the microcontroller is idling in the delay-loop while the contacts bounce.