Analog Pins - ozarchie/BlueBasic GitHub Wiki

Syntax

PINMODE <pin> INPUT [PULLUP|PULLDOWN|ADC]
PINMODE <pin> OUTPUT
<pin> = expression
<variable> = <pin>
ANALOG REFERENCE, INTERNAL|EXTERNAL
ANALOG RESOLUTION, 8|10|12|14

Description

Pin Names

The CC254X has many input and output pins which can be used in a program.
These are managed in three groups -: P0, P1 and P2.
P0 and P1 have 8 pins each (0 to 7) while P2 has 5 pins (0 to 5).
After reset, P0 pins are configured as a general-purpose I/O input with pull-up resistor (except P1.0 and P1.1, which do not have pull-up or pull-down capability)
The output drive strength is 4 mA on all outputs, except for the two high-drive outputs, P1.0 and P1.1, which each have 20-mA output drive strength.
The mode for each pin can be set independently of other pins, but there are a few occasions when pins in the same group must have the same properties.
For example, if one pin in group P0 is set to PULLUP, then no other pin in that group can be set to PULLDOWN.

See http://www.ti.com/lit/ug/swru191f/swru191f.pdf
for a complete guide.

Pins are addressed by group, and pin within that group:
BlueBasic pin naming convention

Examples:

BASIC CC254X
P0(0) Pin P0_0
P1(7) Pin P1_7
P2(0) Pin P2_0

Digital Inputs

PINMODE P0(0) INPUT set a pin for input
P = P0(0) read the pin,
PRINT P and display it
The value 0 or 1 will be returned.

Input pins have the option of being pulled up or pulled down:
PINMODE P0(0) INPUT PULLUP
If the pin is floating, it will now be pulled up internally and so will read as "1" unless actively pulled down by an external device.
PINMODE P0(0) INPUT PULLDOWN
If the pin is floating, it will now be pulled down internally and so will read as "0" unless actively pulled up by an external device.

Digital Outputs

PINMODE P0(0) OUTPUT set a pin for output
P(0) = 1 set the value of the pin
This sets the pin high, while setting the value to 0 will make the pin low.

Analog Inputs

PINMODE P0(0) INPUT ADC enable a pin for analog input
A = P0(0) read the pin,
PRINT A and display it
Values are read from the pin just as if they were digital inputs, but now the pin returns an integer value rather than a simple 0 or 1.
All analog pins share two additional properties; the analog resolution and the analog reference.
By default, analog pins use the internal reference and have a resolution of 14 bits.

To use an external reference, issue the command -:
ANALOG REFERENCE, EXTERNAL

This sets the analog pins to use an external reference.
The external reference must be connected to pin P0(7).

To change the resolution of the ADC, issue the command -:
ANALOG RESOLUTION, 10

This will change the resolution of the conversion to 10-bits ( 0 - 1024 ).
The following resolutions are available: 8 bit, 10 bit, 12 bit and 14 bit.
Note that the CC254X returns a signed value for all ADC conversions.
For the default, 14 bit, resolution the pin will return a value between 0 and 8191.

Example

10 ANALOG REFERENCE, INTERNAL
20 ANALOG RESOLUTION, 12
30 PINMODE P0(0) INPUT ADC
40 PRINT P0(0)
⚠️ **GitHub.com Fallback** ⚠️