Serial Wombat Arduino Library
Public Member Functions | Public Attributes | List of all members
SerialWombat18CapTouch Class Reference

A class that controls a Cap Touch Pin on the Serial Wombat 18AB chip. More...

#include <SerialWombat18CapTouch.h>

Inheritance diagram for SerialWombat18CapTouch:
SerialWombatAbstractButton SerialWombatPin

Public Member Functions

 SerialWombat18CapTouch (SerialWombatChip &serialWombat)
 Instantiate a SerialWombat18CapTouch class on a specified Serial Wombat Chip. More...
 
int16_t begin (uint8_t pin, uint16_t chargeTime, uint16_t delay=10)
 Initialize the SerialWombat18CapTouch instance with a given charge Time in uS. More...
 
int16_t makeDigital (uint16_t touchLimit, uint16_t noTouchLimit)
 Make a cap touch behave like a digital button. More...
 
int16_t makeDigital (uint16_t touchLimit, uint16_t noTouchLimit, uint16_t touchValue, uint16_t noTouchValue, bool invert, uint16_t debounceCount)
 Make a cap touch behave like a digital button. More...
 
int16_t makeAnalog ()
 
bool digitalRead ()
 Returns the debounced state of the input. More...
 
uint16_t readDurationInTrueState_mS ()
 return the number of mS that the debounced input has been in true state More...
 
uint16_t readDurationInFalseState_mS ()
 return the number of mS that the debounced input has been in false state More...
 
bool readTransitionsState ()
 Queries the number of transistions that have occured on the debounced input. More...
 
- Public Member Functions inherited from SerialWombatAbstractButton
 SerialWombatAbstractButton ()
 
- Public Member Functions inherited from SerialWombatPin
 SerialWombatPin (SerialWombatChip &serialWombatChip)
 Instantiates a Serial Wombat Pin. More...
 
 SerialWombatPin (SerialWombatChip &serialWombatChip, uint8_t pin)
 Instantiates a Serial Wombat Pin. More...
 
uint16_t readPublicData ()
 Read the 16 Bit public data associated with this pin. More...
 
void pinMode (uint8_t mode, bool pullDown=false, bool openDrain=false)
 Set pin to INPUT or OUTPUT, with options for pull Ups and open Drain settings. More...
 
void digitalWrite (uint8_t val)
 Set output pin High or Low. More...
 
int digitalRead ()
 Reads the state of the Pin. More...
 
uint16_t writePublicData (uint16_t value)
 Write a 16 bit value to this pin. More...
 
uint8_t pin ()
 Returns the current SW pin number. Used primarily for virtual calls by derived classes. More...
 
uint8_t swPinModeNumber ()
 Returns the Mode number. Used primarily by derived classes to populate packet data. More...
 

Public Attributes

uint16_t transitions = 0
 Number of transitions returned by last call to readTransitionsState() More...
 
- Public Attributes inherited from SerialWombatAbstractButton
uint16_t transitions = 0
 Number of transitions returned by last call to readTransitionsState() More...
 

Additional Inherited Members

- Protected Attributes inherited from SerialWombatPin
uint8_t _pin = 255
 
SerialWombatChip_sw
 
uint8_t _pinMode = 0
 

Detailed Description

A class that controls a Cap Touch Pin on the Serial Wombat 18AB chip.

This class allows a metalic plate with a thin insulating layer to be used as a capacitive touch surface. Items like a coin, PCB board, metal plate, etc can be connected directly to the pin and covered by a thin insulating layer. A finger touch can be detected by the change in capacitance caused by its presence.

The mode can output either analog or digital values back to the host and as public data to other pins. In analog mode the A/D reading at the end of a charge cycle is presented. This value gets smaller when a finger or item causes the capacitance of the sensor to increase. (Smaller A/D values when finger present, higher values when absent).

In digital mode the class is configured with a high and low limit which cause a digital change in hysteresis manner. This is useful when treating the touch sensor like a button. In digital mode the class implements the same interfaces as the SerialWombatDebouncedInput class so that physical buttons and cap touch inputs can be treated equivalently. Settign the high and low limits further apart will decrease the chance of false transitions but will also typically decrease the responsiveness of the sensor.

Output public data values for touched and not touched are configurable. This allows other pin modes to react based on touch. For instance, the touch and not touched values might be set to 0x4000 and 0xC000 so that a servo set to monitor that public data would move back and forth between 25% and 75% of its range depending on whether or not a touch is present.

The final touch value is the result of 8 averaged samples in firmware remove noise.

For particularly noisy signals a debounce option is also avaialble. This requires the specified number of samples to match before a transition is detected. This can help eliminate false transitions but makes the system less reponsive in terms of time to transition after a touch is made or removed.

The Cap touch pin mode in the firmware takes exclusive access to the Microcontroller's A/D hardware for a few milliseconds at a time. This isn't an issue for most users if the default 5ms delay between samples is used. However, it should be considered if multiple Cap Touch pins are being used simultaneously or if the delay is decreased as they may combine to starve other analog chanels and make conversions sporadic, affecting filtering and averaging. This may also impact performance of real-time control pin modes run on the Serial Wombat chip such as PID control.

A Tutorial video is also avaialble: https://youtu.be/c4B0_DRVHs0