basic programming
In our latest unit, we were introduced to programming, or coding, a machine/device to perform a specific task based on something else (a command, switch being touched, light sensor activated etc. We started at a very low (hence "basic") level. We were using Pseudo code in a program called ROBOTC with VEX equipment.
Analog vs. digital
There are two types of signals, Analog and Digital. Analog signals are continuously sending information in multiple different levels (i.e. a light sensor records not only if there is or isn't light, but how much light there is, or isn't). Digital signals only read in 1's and 0's (a bump switch only notes that it is depressed or is not depressed, not how much force is being applied).
input vs output
We used two essential types of devices, inputs and outputs. An input is a device that records a value based on an action taken towards that device. For example, a bump switch records a "1" each time it is bumped, this means that it is a digital device as noted in the previous section. Also, a light sensor can record the amount of light it is exposed to (once again, this would make it an analog device as previously noted).
An out put device is a device that preforms an action based on a command and or value given to it in the code. An example of this would be a Motor or a Servo.
An out put device is a device that preforms an action based on a command and or value given to it in the code. An example of this would be a Motor or a Servo.
coding
In complex coding, you will have at least one code inside of a code. For example:
Task main
{
{While ( 1==1)
TurnMotorOn (port1, 127);
UntilLight (450, in3);
TurnMotorOff (port1, 127);
Wait (5);
TurnMotorOn (port1, 127);
Wait (10);
TurnMotorOff (port1, 127);
}
}
In the previous example, a while loop, I said that as long as 1 is equal to 1, the following should be carried out: Turn on the motor until the Light sensor reads 450, Then turn the motor off for 5 seconds, then turn the motor back on for 10 seconds and then turn the motor off.
An if else statement could be used in a similar way
For example:
Task Main
{
If (X==0)
{
TurnMotorOn (port1, 127);
UntilLight (450, in3);
TurnMotorOff (port1, 127);
Wait (5);
TurnMotorOn (port1, 127);
Wait (10);
TurnMotorOff (port1, 127);
}
{
Else
}
}
In the previous Example, I stated that if X is equal to zero then the following code should be carried out. However if X was not equal to (!=) zero then nothing would be done.
Task main
{
{While ( 1==1)
TurnMotorOn (port1, 127);
UntilLight (450, in3);
TurnMotorOff (port1, 127);
Wait (5);
TurnMotorOn (port1, 127);
Wait (10);
TurnMotorOff (port1, 127);
}
}
In the previous example, a while loop, I said that as long as 1 is equal to 1, the following should be carried out: Turn on the motor until the Light sensor reads 450, Then turn the motor off for 5 seconds, then turn the motor back on for 10 seconds and then turn the motor off.
An if else statement could be used in a similar way
For example:
Task Main
{
If (X==0)
{
TurnMotorOn (port1, 127);
UntilLight (450, in3);
TurnMotorOff (port1, 127);
Wait (5);
TurnMotorOn (port1, 127);
Wait (10);
TurnMotorOff (port1, 127);
}
{
Else
}
}
In the previous Example, I stated that if X is equal to zero then the following code should be carried out. However if X was not equal to (!=) zero then nothing would be done.