TDuino
Convenient functionality for Arduino
Public Member Functions | Protected Member Functions | Protected Attributes
TPin Class Reference

Handles a I/O for a single pin. More...

#include <TPin.h>

Public Member Functions

 TPin ()
 Default constructor for the TPin class. More...
 
virtual void attach (byte pin, byte mode=INPUT)
 Attach the instance of TPin to a pin. More...
 
void enable (byte on)
 Enable / disable a digital pin. More...
 
void flip ()
 Flip pin state. More...
 
void off ()
 Turn off the pin. More...
 
void on ()
 Turn on the pin. More...
 
void pwm (int value)
 Set the pin to a PWM value. More...
 
int read ()
 Read the value from the pin. More...
 
byte state ()
 Get the digital state of the pin. More...
 
bool isAnalog ()
 Checks if the pin is analog. More...
 
bool hasPwm ()
 Checkt if the pin has PWM capabilities. More...
 
byte getMode ()
 Get the pin's mode. More...
 
byte getPin ()
 Get the pin's number. More...
 
- Public Member Functions inherited from TBase
 TBase ()
 Constructor for class TBase. More...
 
virtual ~TBase ()
 Destructor for class TBase. More...
 
virtual void loop ()
 The loop method for TBase and all subclasses. More...
 

Protected Member Functions

bool isPinValid (const char *token=NULL)
 
bool isPwmValid (int &value, const char *token=NULL)
 
- Protected Member Functions inherited from TBase
virtual void defaults ()
 Method used to reset all class internal variables. More...
 

Protected Attributes

byte pin
 The pin assigned to this instance.
 
byte mode
 The mode used for the pin (INPUT / INPUT_PULLUP / OUTPUT). The two high order bits are used to store additional info about the pin.
 
- Protected Attributes inherited from TBase
unsigned long loopMillis
 The value of millis() to be used within loop()
 

Detailed Description

Handles a I/O for a single pin.

TPin is used to handle different I/O tasks for a pin.

Constructor & Destructor Documentation

◆ TPin()

TPin::TPin ( )

Default constructor for the TPin class.

The constructor will set the pin and mode to invalid values. You MUST call TPin::attach() during the setup phase of your sketch before the instance of TPin is of any use.

See also
attach()

Member Function Documentation

◆ attach()

void TPin::attach ( byte  pin,
byte mode  = INPUT 
)
virtual

Attach the instance of TPin to a pin.

Parameters
pinThe pin to which the instance should be attached.
modeThe mode to be used for the pin.

If you are using the default constructor which takes no arguments (eg. if creating an array of TPin), you MUST call attach() on each instance of TPin in order for the pin to work.

attach() will store the values provided as arguments in pin and mode and test wheter the pin is analog and store the value in #analog. When this is done, the mode of the pin will be selected with pinMode().

Reimplemented in TPinInput, TButton, and TPinOutput.

◆ enable()

void TPin::enable ( byte  on)

Enable / disable a digital pin.

Parameters
onShould be LOW (disable) or HIGH (enable)

Uses digitalWrite to set the pins state.

See also
flip() on() off()

◆ flip()

void TPin::flip ( )

Flip pin state.

This will flip / invert the state of the pin. If the pint is LOW it will be set to HIGH vice versa. Uses digitalWrite regardles of the pin being detected as analog.

See also
on() off() enable()

◆ getMode()

byte TPin::getMode ( )

Get the pin's mode.

Returns
The pin mode.

Used to retreive the mode used by the pin. The return value is equal to the mode set in the constructor or with setMode().

See also
TPin().

◆ getPin()

byte TPin::getPin ( )

Get the pin's number.

Returns
The pin number.

Used to retreive the pin number used by this instance of TPin. The value return is equal to the pin number set in the constructor.

See also
TPin().

◆ hasPwm()

bool TPin::hasPwm ( )

Checkt if the pin has PWM capabilities.

Returns
True if the pin has PWM capabilities.

You can use this method to detect is the pin has PWM capabilities. This method must return true if the pwm() method should work with the pin.

See also
pwm().

◆ isAnalog()

bool TPin::isAnalog ( )

Checks if the pin is analog.

Returns
True if the pin is analog.

Returns the value of #analog.

◆ off()

void TPin::off ( )

Turn off the pin.

Sets the pin state to LOW.

See also
flip() on() enable()

◆ on()

void TPin::on ( )

Turn on the pin.

Sets the pin state to HIGH.

See also
flip() off() enable()

◆ pwm()

void TPin::pwm ( int  value)

Set the pin to a PWM value.

Parameters
valueThe PWM value to be set.

Sets the pin's PWM value to the value given. The PWM value is set using analogWrite. To reduce overhead there is being performed no check of the pins PWM capabilities (unless compiled in debug mode). If you need to, you can do this with hasPwm().

◆ read()

int TPin::read ( )

Read the value from the pin.

Returns
The value from the pin.

This will return the value retreived with analogRead for analog pins and digitalRead for digital pins.

See also
state()

◆ state()

byte TPin::state ( )

Get the digital state of the pin.

Returns
The state of the pin.

This will return the state retreived with digitalRead even if the pin is analog.

See also
read()