|
Page 18Digital sensors typically only have two wires and are wired such that when the sensor is triggered theSEN and GND lines complete a circuit. Analog sensors can have two or three wires. For an analogsensor the resistance between the SEN and GND lines will vary. The third wire is connected to VCC topower the sensor if the sensor requires a power source in order to operate (e.g., a reflectance sensorhas an IR emitter which has to be powered to work).The voltage on the KIPR Link from VCC to GND is set to +5V for both digital and analog ports. The voltagerange between SEN and GND is also +5V for both digital and analog ports. The +5V setting is establishedby internal jumper settings, and opening the case to change them will void your warranty. It issuggested that you first contact KIPR Technical Support if you think this is something your applicationrequires. Instructions for accessing the jumpers are in the appendix as are specifications for creatingyour own sensors.KIPR Link Library Functions for SensorsThe two most basic library functions for using sensors with the KIPR Link are the analog10 and digitalfunctions.analog10()Analog sensors produce a varying voltage value as resistance between SEN and GND varies.analog10 returns the analog value of the port (a value in the range 0-1023). Analog ports arenumbered 0-7. Light sensors and range sensors are examples of sensors you would use in analogports. The following example is for a light sensor plugged into analog port 3:printf("Light sensor reading is %d\n", analog10(3));digital()Digital sensors operate like a switch, effectively producing a resistance value between SEN andGND of either none (switch closed) or ∞(switch open). The digital function returns 0 if theswitch is open (∞ resistance) and 1 if the switch is closed (no resistance). The digital ports onthe KIPR Link are numbered 8-15. Touch sensors are typical digital sensors, commonly used forbumpers or limit switches. The following example is for a button (touch) sensor plugged intoport 8:if (digital(8)==1)printf("button is being pressed\n");elseprintf("button is not being pressed\n");The C language prototypes for these two functions are:int analog10(int port_no);int digital(int port_no);
PreviousNext |