Car motion with NXC
Please building a basic car before we write the code.In this project, we will let the car forward for 1 second. This program will use the functions : task main(){}, OnFwd(Ports, Power), Wait(ms), Off(Ports).
task main(){}
This is the main function for a NXC program. The program begin from the function.task main()
{
statements.
}
OnFwd(Port/s, Power)
This will control the car to forward if you build the orientation of motor as same as the NXC.Ports: setting the port or ports (OUT_A,OUT_B,OUT_C,OUT_AB,OUT_AC,OUT_BC,OUT_ABC,) which you want to control.
Power: setting the power of the motor or motors.
OnFwd(Ports, Power)
Wait(ms)
This will let the car pause for the time which you set.Wait(ms)
Off(Port/s)
This will turn off the motor or motors.Ports: setting the port or ports (OUT_A,OUT_B,OUT_C,OUT_AB,OUT_AC,OUT_BC,OUT_ABC,) which you want to control.
Off(Ports)
Example:
task main()
{
OnFwd(OUT_AC,100);
Wait(1000);
Off(OUT_AC);
}