.NET Gadgeteer Display Simple Graphics

This example uses the GHI Electronics Display_T35 module, the Potentiometer, and a Button to demonstrate use of the Display Module Simple Graphics interface.  The application displays circles, or symmetrical ellipses, on an orange background based on the coordinates of a Window.TouchDown event. The size of the circle is determined by the potentiomenter setting.

    void window_TouchDown(object sender, Microsoft.SPOT.Input.TouchEventArgs e)
    {
        int x;
        int y;
        // Use the out parameters to get the position of touch.
        e.GetPosition(window, 0, out x, out y);

        double potSetting = potentiometer.ReadPotentiometerPercentage();
        // Multiply by 100 to get into integer range before conversion.
        display.SimpleGraphics.DisplayEllipse(GT.Color.Green, (uint)x, (uint)y,
                                   (uint)(potSetting * 100), (uint)(potSetting * 100));

    }

The Display_T35 touch screen displays circles where a touch occurs, as shown in the following illustration. To clear the display, push the button.

Display Simple Graphics

Display Simple Graphics

All the applicatoin code is in the Program.cs file as follows:

using System;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;

using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Gadgeteer.Modules.GHIElectronics;

namespace GadgeteerDisplayGraphics
{
    public partial class Program
    {
        Window window;
        void ProgramStarted()
        {
            window = display.WPFWindow;
            display.SimpleGraphics.BackgroundColor = GT.Color.Orange;

            window.TouchDown += new Microsoft.SPOT.Input.TouchEventHandler(window_TouchDown);
            button.ButtonPressed += new Button.ButtonEventHandler(button_ButtonPressed);
            Debug.Print("Program Started");
        }

        void button_ButtonPressed(Button sender, Button.ButtonState state)
        {
            display.SimpleGraphics.Clear();
        }

        void window_TouchDown(object sender, Microsoft.SPOT.Input.TouchEventArgs e)
        {
            int x;
            int y;
            // Use the out parameters to get the position of touch.
            e.GetPosition(window, 0, out x, out y);

            double potSetting = potentiometer.ReadPotentiometerPercentage();
            // Multiply by 100 to get into integer range before conversion.
            display.SimpleGraphics.DisplayEllipse(GT.Color.Green, (uint)x, (uint)y,
                                     (uint)(potSetting * 100), (uint)(potSetting * 100));

        }
    }
}

Advertisements
  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: