IoT

IoT: La nostra prima applicazione














<StackPanel HorizontalAlignment=”Center” VerticalAlignment=”Center”>
    <Ellipse x:Name=”LED” Fill=”LightGray” Stroke=”White” Width=”100″ Height=”100″ Margin=”10″/>
    <TextBlock x:Name=”GpioStatus” Text=”Waiting to initialize GPIO…” Margin=”10,50,10,10″ TextAlignment=”Center” FontSize=”26.667″ />
    <Button Name=”AccendeSpegneLEDButton” Content=”Accendi LED” HorizontalAlignment=”Center” Click=”AccendeSpegneLEDButton_Click”/>
</StackPanel>

// Copyright (c) Microsoft. All rights reserved.
using System;
using Windows.Devices.Gpio;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Media;
namespace Blinky
{
    public sealed partial class MainPage : Page
    {
        private const int LED_PIN = 5;
        private GpioPin pin;
        private GpioPinValue pinValue;
        private SolidColorBrush yellowBrush = new SolidColorBrush(Windows.UI.Colors.Yellow);
        private SolidColorBrush grayBrush = new SolidColorBrush(Windows.UI.Colors.LightGray);
        public MainPage()
        {
            InitializeComponent();
            InitGPIO();
        }
        private void InitGPIO()
        {
            var gpio = GpioController.GetDefault();
            // Show an error if there is no GPIO controller
            if (gpio == null)
            {
                pin = null;
                GpioStatus.Text = “Non c’è il GPIO controller su questo device.”;
                return;
            }
            pin = gpio.OpenPin(LED_PIN);
            pinValue = GpioPinValue.High;
            pin.Write(pinValue);
            pin.SetDriveMode(GpioPinDriveMode.Output);
            GpioStatus.Text = “GPIO pin correttamente inizializzati.”;
        }
        private void AccendeSpegneLEDButton_Click(object sender, RoutedEventArgs e)
        {
            if (pinValue == GpioPinValue.High)
            {
                pinValue = GpioPinValue.Low;
                pin.Write(pinValue);
                LED.Fill = yellowBrush;
                AccendeSpegneLEDButton.Content = “Spegni LED”;
            }
            else
            {
                pinValue = GpioPinValue.High;
                pin.Write(pinValue);
                LED.Fill = grayBrush;
                AccendeSpegneLEDButton.Content = “Accendi LED”;
            }
        }
    }
}  






Articoli Correlati

Come mettere in sicurezza il proprio router, NAS o dispositivo IoT?

Amazon Echo e Kindle vulnerabili all’attacco KRACK: milioni di utenti a rischio

WPS: come controllare se il nostro router è vulnerabile