Lab 5

Lab Description:

What is Phidgets? Phidgets is where basic programming and microcontrollers meet. The best part about Phidgets is the elimination of soldering and the usage of USB devices. Phidgets utilizes an micro-controller (Phidget Interface Kit 8/8/8 (P/N 1018)) where various different inputs can be attached to it and manipulated through various forms of programming such as C++, C, Java, Visual Basic and etc. The purpose of this laboratory is to explore this world and create a very simple program. Installation of the Phidgets library was needed and is supported by many platforms such as Linux, Windows, Android and etc. For Linux enviroments, the kernel has to be 2.6 or newer. My team chose the sensor aspect of this and implemented a program where it will continuously display the readings until the user hits Enter. The program can read any sensor data since the micro-controller treats all analog attachments the same. The sensors will send an electrical reading back and hence interpretation of the data will be the same. The differences between readings will be dependent on the sensor. For example, the Rotation Sensor (P/N 1109) can rotate 300 degrees but will give readings of 1-1000. Manipulation of this data via mathematical formulas will vary depending on the application of the sensor.

Code:

//Header
#include 
#include 

//Event Handler
int SensorChangeHandler(CPhidgetInterfaceKitHandle IFK, void *usrptr, int index, int value){

printf("Sensor: %d > value: %d\n", index, value);
return 0;
}

//Main Function
int main(int argc, char* argv[]){

//Variable Declarations
char input;
int val, i;

//creates the interface
CPhidgetInterfaceKitHandle ifKit = 0;
CPhidgetInterfaceKit_create(&ifKit);
CPhidget_open((CPhidgetHandle)ifKit, -1); //reads data from all ports that any device is attached

CPhidget_waitForAttachment((CPhidgetHandle)ifKit, 10000); //waits for attachment

CPhidgetInterfaceKit_set_OnSensorChange_Handler (ifKit, SensorChangeHandler, NULL); //calls function

//while loop that will display data until user hits enter.
printf("Welcome to my Sensor Reading Program... \n");
printf("Hit Enter to Exit \n");
while(input != '\n') {
CPhidgetInterfaceKit_getSensorValue(ifKit, 0, &val);
printf("Value: %d\n", val);
scanf("%c", &input);
}

printf("Thank you for using my program... \n");

return 0;
}

Screenshot:

Screenshot from 2014-04-30 22:05:35