Controlling the Hardware
Some of the components that you can build to increase and monitor the performance of your car have library functions defined that simplify their usage tremendously. They are all described in detail in the IC Manual, but due to version changes, a few commands are not correct. Here we will cover those functions and introduce a few of the more important ones that you will need. This page should contain all the information you need to implement your car.
void motor(int m, int p)where m is the motor port number and p is the power. Using the special motor drivers, a power of -100 turns the motor off and 100 runs it at full speed.
C> load servo.cThe servo can then be positioned to any degree point around a circle. The function:
servo_on();enables the servo and allows calls to:
servo(int p)to position the servo at a radial position denoted in radians by p;
enable_encoder(int p)initializes an encoder on digital port p. Ports 0 and 1 are the reccommended ports for encoders. This function sets a variable, port0_shaft_count (assuming port 0 was used) that counts the number of pulses generated by the encoder. The sampling rate is 1000 Hz (1000 times a second). This varibale can be set to anything you want since it is just a global varibale defined on the board. For instance, if if you want to find out how many rotations happen while a loop is exectuing, set the variable to 0 at the beginning of the loop and read the value at the end of the loop.
int dip_switch(int s)returns the value, 1 for on and 0 for off, of switch s.
int digital(int p)returns a 1 or 0 depending on the state of the sensor on port p.
int analog(int p)returns a number from 0 to 255 indicating the voltage range across port p.
void reset_system_time()sets the system time to 0. The two commands,
long mseconds() float seconds()return the system time in milliseconds and seconds, resp, and
void sleep(float sec)waits sec seconds before continuing with the program.