Controlling Servo Motor

Servo Sample Connectivity

In this blog post, I’ll show you how to control a servo motor with a UWP App installed on a Raspberry Pi 2, running Windows 10 IoT Core.

Step One:

You need to connect your Servo Motor to the Raspberry Pi 2 as show in scheme:

Servo Sample Scheme

Step Two:

Now, you should write the code that will control the servo motor, you will find the source code HERE
Clone this code, and you will find two methods: PWM_R() which will make the servo motor rotate to the right and PWM_L() which will make the servo motor rotate to the left.

and you’ll find also the event handler which will be invoked each time you press the push button.

 

And here’s a video of the result you should get:

Advertisements

Integrating Cortana | Part 1

CortanaIn this blog, you will learn How to integrate Cortana into your Windows Phone 8.1 Runtime App.
But, before you integrate Cortana, you have to know Who is Cortana?
So, let me introduce Cortana to you, or actually she will 😀

Who is Cortana?

Cortana is your Digital Personal Assistant, it was developed by Microsoft for Windows Phone 8.1, Microsoft Band and it will be available in Windows 10.
Cortana was announced for the first time at Microsoft BUILD Developer Conference April 2014 and before that she was a character in Halo video game series.

If you have a Windows Phone Device, try asking Cortana “Who are you?” and “Tell me more about yourself.” 😉

Cortana’s Core Functions

Cortana has Three Core Functions:

  1. Communicate
    It can make a call, send text message and text dictation task and so on.
  2. Reminder
    Help the user complete the task now, or help them remember for later.
  3. Find
    Finding content in large catalogs, from large lists, etc…

What can Cortana do?

If you have a Windows Phone Device, try asking Cortana the below commands between the double quotations. Continue reading

Using Bing Maps

Using Bing maps inside your app might be very important and amazing feature that rates up your app in the store so, let’s know how to add Bing Maps to your Windows Store App.

First of all you will need to install “Bing Maps for windows Store C#” from the following URL:
http://visualstudiogallery.msdn.microsoft.com/224eb93a-ebc4-46ba-9be7-90ee777ad9e1

Then, Go to this website and register to get a Bing Maps  Key (You will need it inside your App each time you use bing maps)
http://www.microsoft.com/maps/create-a-bing-maps-key.aspx

Select Basic Key, then click on “Get the Basic Key” (as shown)
b6

Then, follow the steps to register,

Continue reading

05 C# Data Types

And now we’re going to talk about C# Data Types and C# Type Conversion

In C#, variables are categorized into the following types:

  • Value types
  • Reference types
  • Pointer types

Value Types
Value type variables can be assigned a value directly. They are derived from the class System.ValueType. The value types directly contain data. Some examples are int, char, float, which stores numbers, alphabets, floating point numbers, respectively. When you declare an int type, the system allocates memory to store the value.

The kink below declares a table lists the available value types in C#
http://sdrv.ms/1fDrJML

To get the exact size of a type or a variable on a particular platform, you can use the sizeof method. The expression sizeof(type) yields the storage size of the object or type in bytes. Following is an example to get the size of int type on any machine:

using system;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DataTypeApplication
  {
    class Program
      {
        static void Main(string[] args)
          {
            Console.WriteLine("Size of int: {0}", sizeof(int));
            Console.ReadLine();
          }
      }
  }

When the above code is compiled and executed, it produces the following result:
size

Reference Types
The reference types do not contain the actual data stored in a variable, but they contain a reference to the variables.
In other words, they refer to a memory location. Using more than one variable, the reference types can refer to a memory location. If the data in the memory location is changed by one of the variables, the other variable automatically reflects this change in value. Example of built-in reference types are: object, dynamic and string.

OBJECT TYPE
The Object Type is the ultimate base class for all data types in C# Common Type System (CTS). Object is an alias for System.Object class. So object types can be assigned values of any other types, value types, reference types, predefined or user-defined types. However, before assigning values, it needs type conversion. When a value type is converted to object type, it is called boxing and on the other hand, when an object type is converted to a value type, it is called unboxing.

DYNAMIC TYPE
You can store any type of value in the dynamic data type variable. Type checking for these types of variables takes place at runtime. Dynamic types are similar to object types except that type checking for object type variables takes place at compile time, whereas that for the dynamic type variables takes place at run-time.

STRING TYPE
The String Type allows you to assign any string values to a variable. The string type is an alias for the System.String class. It is derived from object type.

 

Pointer Types
Pointer type variables store the memory address of another type. Pointers in C# have the same capabilities as in C or C++.
Syntax for declaring a pointer type is:

type*  identifier;

For Example:

char* cptr;
int* iptr;

And now we have already discussed the C# Data Types 🙂

So. it’s the time to know C# Type Conversions 

Type conversion is basically type casting or converting one type of data to another type. In C#, type casting has two forms:

  •  Implicit type conversion – these conversions are performed by C# in a type-safe manner. Examples are conversions from smaller to larger integral types and conversions from derived classes to base classes.
  •  Explicit type conversion – these conversions are done explicitly by users using the pre-defined functions. Explicit conversions require a cast operator.

The following example shows an explicit type conversion:

namespace TypeConversionApplication</pre>
{
class ExplicitConversion
{
static void Main(string[] args)
{
double d = 5673.74;
int i;
// cast double to int.
i = (int)d;
Console.WriteLine(i);
Console.ReadKey();
}
}
}

 

C# Type Conversion Methods
The link below declares the built-in type conversion methods:
http://sdrv.ms/1bwg2Fi

The following example converts various value types to string type:

namespace TypeConversionApplication
 {
     class StringConversion
     {
         static void Main(string[] args)
         {
             int i = 75;
             float f = 53.005f;
             double d = 2345.7652;
             bool b = true;
             Console.WriteLine(i.ToString());
             Console.WriteLine(f.ToString());
             Console.WriteLine(d.ToString());
             Console.WriteLine(b.ToString());
             Console.ReadKey(); 
         }
     }
 }

 

And now we have already finished our lesson 🙂
Next time we will talk about exciting topic so, Stay tuned 🙂
And if you need any help or support, Feel free to contact me 🙂