Windows on Device Project Practice 1, ondevice

Source: Internet
Author: User

Windows on Device Project Practice 1, ondevice

In the previous article "Wintel IoT platform-getting started with Windows IoT", we explained the Windows on Device hardware preparation and the establishment of the software development environment, as well as the demonstration of the Hello Blinky project. At the beginning of this article, we will go to the Project Practice section.

Because Galileo is the hardware platform designed for Windows on Device, its peripheral interfaces are also compatible with the Arduino standard. In addition, the programming mode also refers to the Wiring Language used in Arduino.

1. PWM Principle

Pulse Width Modulation is generally called PWM. Pulse Width Modulation (PWM) is a digital coding method for analog signal levels. Because the computer cannot output analog voltage, it can only output 0 or 5 V digital voltage values, we use a high-resolution counter and the duty cycle of the square wave to encode the level of a specific analog signal. The PWM signal is still numerical, because at any given moment, the DC power supply with Full amplitude is either 5 V (ON) or 0 V (OFF ). A voltage or current source is added to a simulated load using a repeating pulse sequence of ON or OFF. When the DC power supply is added to the load, when the power supply is disconnected. If the bandwidth is sufficient, any analog value can be encoded using PWM. The output voltage value is calculated based on the switching time. Output voltage = (connection time/pulse time) * Maximum voltage value.

PWM is used in many places, such as dimming lamps, motor speed regulation, and sound production. The three basic parameters of PWM are as follows:

  • 1. Amplitude of pulse width variation (minimum/maximum)
  • 2. Pulse cycle (reciprocal of the number of pulse frequencies in one second)
  • 3. Voltage height (for example, 0 V-5 V)

The Arduino controller has six PWM interfaces: digital interfaces 3, 5, 6, 9, 10, and 11. Likewise, these interfaces support PWM output on Galileo.

2. Component and hardware connection

Components required for this practical project include:

  • Potentiometer module * 1
  • Direct LED * 1
  • 220 Ω direct insertion Resistance
  • Bread * 1
  • Bread board jumper

As the analog value input of Galileo, the potentiometer is connected to the analog port. The LED lamp is connected to the PWM interface, so that different PWM signals can be generated to change the brightness of the small lamp.

The schematic diagram and hardware diagram of the connection are as follows:

 

 

 

3. source code parsing

During program writing, we will use the analog write analogWrite (PWM interface, analog value) function. For the analog write analogWrite () function, this function is also easy to use, in this experiment, we read the analog value signal of the potentiometer and assigned it to the PWM interface so that the light brightness changes accordingly, and then the read analog value is displayed on the screen, you can understand that this program adds the simulated value to the PWM interface in the experiment program for reading the simulated value. Below is a source program for reference, analog Input interfaces 0 and digital interfaces 11 are used.

// Main. cpp: Defines the entry point for the console application.
//

# Include "stdafx. h"
# Include "arduino. h"

Int _ tmain (int argc, _ TCHAR * argv [])
{
Return RunArduinoSketch ();
}

Int potpin = 0; // defines the simulation interface 0
Int ledpin = 11; // defines the digital interface 11 (PWM output)
Int val = 0; // Save the variable value from the sensor

Void setup ()
{
// TODO: Add your code here
PinMode (ledpin, OUTPUT); // defines the digital interface 11 as the OUTPUT
// Note: The simulation interface is automatically set as input.
}

// The loop routine runs over and over again forever:
Void loop ()
{
// TODO: Add your code here

Val = analogRead (potpin); // read the analog value of the potentiometer and assign it to val
Log (L "val: % d \ r \ n", val); // output the value in the debugging window
AnalogWrite (ledpin, val/4); // turn on the LED and set the brightness (the maximum PWM output value is 255)
Delay (10); // delay: 0.01 seconds

}

4. debugging results

Start Galileo, use TelNet to establish a connection, and then click debug. The program will be downloaded to Galileo through the network port. We turn the knob of the potentiometer to see not only the changes in the value on the screen, but also the brightness of the LED light on our bread.

Debugging video links as follows, you can look at the effect of the Light: http://v.youku.com/v_show/id_XODU0NjY1OTQw.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.