Touch Screen

The display we have used also has a touch screen. This can detect where someone has touched it. We are going to use a touch on the screen to change the time interval. Each time the screen is tapped, it will step along to the next time interval from an array of time intervals. Finally, when it gets to the end of the list it will change to a setting of “Camera Off.”

Detecting a touch on the screen is as simple as adding this line to SetupUI:

mainWindow.TouchDown += new Microsoft.SPOT.Input.TouchEventHandler(mainWindow_TouchDown);

Now, whenever the screen is touched, mainWindow_TouchDown will be called.

To be able to cycle through a series of intervals, we use the following data structure:

int[] intervals = {0, 5, 10, 20, 30, 60};

This creates an array of interval values in seconds. We then use another variable (intervalPosition) to identify the current interval. Then, when we want to move onto the next interval, we increment intervalPosition until we get to the end of the list and then go back to 0. An interval of 0 will have the special meaning of “Camera Off.”

We can see this in the mainWindow_TouchDown handler:

void mainWindow_TouchDown(object sender, Microsoft.SPOT.Input.TouchEventArgs e)
{
    intervalPosition++;
    if (intervalPosition == intervals.Length)
    {
        intervalPosition = 0;
    }
    setTimerInterval(intervalPosition);
}

Changing the interval of the timer itself occurs in the method setTimerInterval:

void setTimerInterval(int newIntervalPosition) { intervalPosition = newIntervalPosition; ...

Get Getting Started with .NET Gadgeteer now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.