Coder Social home page Coder Social logo

AnalogRead error about remote-wiring HOT 2 CLOSED

edgardmi avatar edgardmi commented on July 18, 2024
AnalogRead error

from remote-wiring.

Comments (2)

edgardmi avatar edgardmi commented on July 18, 2024

Sorry... I found the solution #69

My code now:

`
using System;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Microsoft.Maker.Serial;
using Microsoft.Maker.RemoteWiring;
using Microsoft.Maker.Firmata;

namespace Raspberry
{

public sealed partial class MainPage : Page
{
    private UsbSerial usb;
    private RemoteDevice arduino;
    private const byte led1 = 13;
    private DispatcherTimer readTemperatureTimer;

    public MainPage()
    {
        this.InitializeComponent();

        usb = new UsbSerial("VID_0403", "PID_6001");
        arduino = new RemoteDevice(usb);
        arduino.DeviceReady += onDeviceReady;

        usb.begin(57600, SerialConfig.SERIAL_8N1);
    }

   

    private void onDeviceReady()
    {
        var action = Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, new Windows.UI.Core.DispatchedHandler(() =>
        {
            setup();
        }));
    }

    private void setup()
    {
        //Set the pin mode of the led.
        arduino.pinMode(led1, PinMode.OUTPUT);
        arduino.pinMode("A0", PinMode.ANALOG);
        textConnection.Text = "Connected";
        //Set the timer to schedule every 500 ms.
        readTemperatureTimer = new DispatcherTimer();
        readTemperatureTimer.Interval = TimeSpan.FromMilliseconds(1000);
        readTemperatureTimer.Tick += readTemperature;
        readTemperatureTimer.Start();
    }

    private void Onbutton_Click(object sender, RoutedEventArgs e)
    {
        arduino.digitalWrite(led1, PinState.HIGH);
        Onbutton.Visibility = Visibility.Collapsed;
        Offbutton.Visibility = Visibility.Visible;
    }

    private void Offbutton_Click(object sender, RoutedEventArgs e)
    {
        arduino.digitalWrite(led1, PinState.LOW);
        Offbutton.Visibility = Visibility.Collapsed;
        Onbutton.Visibility = Visibility.Visible;
    }

    private void readTemperature(object sender, object e)
    {
        //Read analog value from 0 to 1023, which maps from 0 to 5V
        int temperatureValue = arduino.analogRead("A0");

        //Convert analog value to temperature.
        double temperature = (500.0 * temperatureValue) / 1024.0;

        //Print temperature to Output.
        textTemp1.Text = temperature.ToString() ;
    }
}

}
`

from remote-wiring.

IoTGirl avatar IoTGirl commented on July 18, 2024

Hi Edgar,
Since you have solved this issue, you can close this unless you have any further questions.
Sincerely,
IoTGirl

from remote-wiring.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.