Language - C Windows CodeBlocks: Difference between revisions

From Phidgets Support
(Created page with "{{NoTitle}} {{Language_-_C_Dev_Environment_Table}} {| |style="vertical-align:middle; width: 60%;"| <font size=6>'''Language - C''' '''Windows with Code::Blocks'''</font> Wel...")
 
No edit summary
(8 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{NoTitle}}
{{NoTitle}}
{{Language_-_C_Dev_Environment_Table}}
{|
{|
|style="vertical-align:middle; width: 60%;"|
|style="vertical-align:middle; width: 60%;"|
Line 14: Line 13:
{{Language_-_C_Intro|Windows|Code::Blocks}}
{{Language_-_C_Intro|Windows|Code::Blocks}}


==Use Our Examples==
{{Finding Code Samples|C}}
One of the best ways to start programming with Phidgets is to use our example code as a guide. In order to run the examples, you will need to download and install [http://www.codeblocks.org/downloads Code::Blocks].
 
 
Now that you have Code::Blocks installed, select an example that will work with your Phidget:
*{{SampleCode|C|C Examples}}


==Setting up a New Project==
When you are building a project from scratch, or adding Phidget functionality to an existing project, you'll need to configure your development environment to properly link the Phidget C library.


Open the example in Code::Blocks (you do not need to create a new project) and navigate to Settings -> Compiler... as shown in the image below:
To start, open Code::Blocks, and navigate to Settings -> Compiler... as shown in the image below:


[[Image:C_codeblocks_settings.png|link=|center]]
[[Image:C_codeblocks_settings.png|link=|center]]
Line 39: Line 35:




Finally, from the Global compiler settings screen, navigate to Linker settings and add the following line:
From the Global compiler settings screen, navigate to Linker settings and add the following line:
*phidget22
*phidget22


Line 45: Line 41:




You can now build and run the example:
Next, create a new Console Application project, as follows:
 
[[Image:C_codeblocks_console_application.png|link=|center]]


[[Image:C_codeblocks_run.png|link=|center]]


{{Edit_the_Examples}}
Name your project, and finish creating the project.


{{Language_-_C_Write_Code}}
[[Image:C_codeblocks_name_project.png|link=|center]]


==Setting up a New Project==
When you are building a project from scratch, or adding Phidget functionality to an existing project, you'll need to configure your development environment to properly link the Phidget C library.


Now your project is created, and you can open the generated main.c to begin coding.


To include the Phidget C library, add the following line to your code:
To include the Phidget C library, add the following line to your code:
Line 62: Line 58:
</syntaxhighlight>
</syntaxhighlight>


You can now compile the file as shown in the [[#Use Our Examples|Use Our Examples]] section.
Your project now has access to the Phidget libraries.
 
==Using the Code Samples==
Now that you have configured a project to use Phidgets, you can copy the code sample from the [{{server}}/?view=code_samples&lang=C Code Samples] page into your project, and run it.


{{Language_-_C_Further_Reading}}
{{Language Page What's Next}}

Revision as of 21:10, 16 October 2019

Language - C

Windows with Code::Blocks

Welcome to using Phidgets with C! By using C, you will have access to the complete Phidget22 API, including events.

Code::Blocks is a free, open source cross-platform IDE that can be used for C and C++.

Install Phidget Drivers for Windows

Before getting started with the guides below, ensure you have the following components installed on your machine:

  1. You will need the Phidgets Windows Drivers

Finding Code Samples

To find the code sample to use for your Phidget, navigate to the Code Samples page and select your device from the drop-down menu.

C sample code.jpg


Once you select your device, the code sample generator will give you a working code sample, and a selection of options to customize it to your needs.

Setting up a New Project

When you are building a project from scratch, or adding Phidget functionality to an existing project, you'll need to configure your development environment to properly link the Phidget C library.

To start, open Code::Blocks, and navigate to Settings -> Compiler... as shown in the image below:

C codeblocks settings.png


From the Global compiler settings screen, navigate to Search directories -> Compiler and add the following directory:

  • C:\Program Files\Phidgets\Phidget22
C codeblocks compiler.PNG


Next, select Search directories -> Linker and add the following directory:

  • C:\Program Files\Phidgets\Phidget22\x86
C codeblocks linker.PNG


From the Global compiler settings screen, navigate to Linker settings and add the following line:

  • phidget22
C codeblocks libraries.PNG


Next, create a new Console Application project, as follows:

C codeblocks console application.png


Name your project, and finish creating the project.

C codeblocks name project.png


Now your project is created, and you can open the generated main.c to begin coding.

To include the Phidget C library, add the following line to your code:

#include <phidget22.h>

Your project now has access to the Phidget libraries.

Using the Code Samples

Now that you have configured a project to use Phidgets, you can copy the code sample from the Code Samples page into your project, and run it.

What's Next?

Now that you have set up Phidgets to work with your programming environment, we recommend you read our guide on Phidget Programming Basics to learn the fundamentals of programming with Phidgets.Next Arrow.png