Language - C Windows CodeBlocks: Difference between revisions

From Phidgets Support
No edit summary
No edit summary
Line 1: Line 1:
[[Category:Language]]{{NoTitle}}
{{NoTitle}}
{|
{|
|style="vertical-align:middle; width: 60%;"|
|style="vertical-align:middle; width: 60%;"|
Line 13: 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}}
 
 
Next, open Code::Blocks, and navigate to Settings -> Compiler... as shown in the image below:
 
[[Image:C_codeblocks_settings.png|link=|center]]
 
 
From the Global compiler settings screen, navigate to Search directories -> Compiler and add the following directory:
*C:\Program Files\Phidgets\Phidget22
 
[[Image:C_codeblocks_compiler.PNG|link=|center]]
 
 
Next, select Search directories -> Linker and add the following directory:
*C:\Program Files\Phidgets\Phidget22\x86
 
[[Image:C_codeblocks_linker.PNG|link=|center]]
 
 
From the Global compiler settings screen, navigate to Linker settings and add the following line:
*phidget22
 
[[Image:C_codeblocks_libraries.PNG|link=|center]]
 
Next, create a new Console Application project, as follows:
 
[[Image:C_codeblocks_console_application.png|link=|center]]
 
Name your project, and finish creating the project.
 
[[Image:C_codeblocks_name_project.png|link=|center]]
 
Next, remove main.c from the created project.
 
[[Image:C_codeblocks_remove_main.png|link=|center]]
 
Copy the files from your downloaded example and paste them into the project directory.
 
[[Image:C_codeblocks_project_directory.png|link=|center]]
 
Add the example C file, and PhidgetHelperFunctions.c to the project.
 
[[Image:C_codeblocks_project_with_files.png|link=|center]]
 
Lastly, you'll need to add the common directory to your project search directories. Right-click your project:
 
[[Image:C_codeblocks_project_build_options.png|link=|center]] 
 
Then add the common directory under "Search directories":
[[Image:C_codeblocks_add_project_directory.png|link=|center]]
 
You can now build and run the example:
 
[[Image:C_codeblocks_run.png|link=|center]]
 
{{Edit_the_Examples}}
 
{{Language_-_C_Editing_The_Examples}}


==Setting up a New Project==
==Setting up a New Project==
Line 122: Line 59:


Your project now has access to the Phidget libraries.
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 Page What's Next}}
{{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