|
TDuino
Convenient functionality for Arduino
|
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() | |
Handles a I/O for a single pin.
TPin is used to handle different I/O tasks for a pin.
| 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.
|
virtual |
Attach the instance of TPin to a pin.
| pin | The pin to which the instance should be attached. |
| mode | The 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.
| void TPin::enable | ( | byte | on | ) |
| void TPin::flip | ( | ) |
| byte TPin::getMode | ( | ) |
Get the pin's 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().
| byte TPin::getPin | ( | ) |
| bool TPin::hasPwm | ( | ) |
| bool TPin::isAnalog | ( | ) |
Checks if the pin is analog.
Returns the value of #analog.
| void TPin::pwm | ( | int | value | ) |
Set the pin to a PWM value.
| value | The 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().
| int TPin::read | ( | ) |
Read the value from the pin.
This will return the value retreived with analogRead for analog pins and digitalRead for digital pins.
| byte TPin::state | ( | ) |
Get the digital state of the pin.
This will return the state retreived with digitalRead even if the pin is analog.
1.8.15