Difference between revisions of "ARDUINO MEGA Functions Sensors"

From ROBOTC API Guide
Jump to: navigation, search
(SensorValue)
(SensorValue)
Line 49: Line 49:
 
|-
 
|-
 
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|([[Data_Types#dataType_word|word]])  This array value will return and modify the value of the sensor. When a pin is set as an "input" the SensorValue array command will return the value from the sensor attached to that pin. When a pin is set as an "output", the SensorValue array can be written to set the output value of the pin (typically Digital Outs will be set to 0 for Low and 1 for High).
 
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|([[Data_Types#dataType_word|word]])  This array value will return and modify the value of the sensor. When a pin is set as an "input" the SensorValue array command will return the value from the sensor attached to that pin. When a pin is set as an "output", the SensorValue array can be written to set the output value of the pin (typically Digital Outs will be set to 0 for Low and 1 for High).
 +
  
 
{| class="parameterTable" cellpadding="5%" width="100%"
 
{| class="parameterTable" cellpadding="5%" width="100%"
Line 60: Line 61:
 
   |-
 
   |-
 
   |}
 
   |}
 +
  
 
   {|
 
   {|
 
   |-
 
   |-
 
   |<syntaxhighlight lang="robotc">
 
   |<syntaxhighlight lang="robotc">
while(SensorValue(touchSensor) == 0) //Loop while robot's bumper/touch sensor isn't pressed in
+
while(SensorValue[dgtl6] == 0) //Loop while digital pin #6 is low (set to zero)
 
{
 
{
   motor[rightMotor] = 63;  // Right motor is run at half (63) power forward
+
   motor[motor_2] = 63;  // Motor pin #2 is run at half (63) power forward
   motor[leftMotor]  = 63;  // Left motor is run at half (63) power forward
+
   motor[motor_3]  = 63;  // Motor pin #3 is run at half (63) power forward
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>

Revision as of 02:03, 10 May 2012

ARDUINOFunctions and Variables → ARDUINO MEGA Functions Sensors
Color Key
Function:
Variable:


Information

The Arduino MEGA has 16 analog sensor ports and 53 digital sensor ports.


SensorType

TSensorTypes SensorType[tSensors sensor]
(TSensorTypes) The SensorType array is used to specify what type of sensor is connected to a certain port. Most users should not have to use this functionality and should use the Motors and Sensor Setup instead.


Parameter Explanation Data Type
sensor A sensor port or name tSensors


SensorType[sonarSensor] = sensorSonar;  // set 'SonarSensor' to be of type sensorSonar (the Motors and 
                                        // sensors Setup screen does this for you in the background)


SensorValue

word SensorValue[tSensors sensor]
(word) This array value will return and modify the value of the sensor. When a pin is set as an "input" the SensorValue array command will return the value from the sensor attached to that pin. When a pin is set as an "output", the SensorValue array can be written to set the output value of the pin (typically Digital Outs will be set to 0 for Low and 1 for High).


Parameter Explanation Data Type
sensor A sensor port or name tSensors


while(SensorValue[dgtl6] == 0) //Loop while digital pin #6 is low (set to zero)
{
   motor[motor_2] = 63;   // Motor pin #2 is run at half (63) power forward
   motor[motor_3]  = 63;   // Motor pin #3 is run at half (63) power forward
}