Arduino library that makes handling Input and Output easier. There are many useful features for using buttons, encoders and triggers.
#include "Arduino.h"
#include <Input.h>
#include <Output.h>
#include <Execute.h>
Input enc1 = Input(0);
Input inp1 = Input(1);
Input inp2 = Input(2, "Input2");
Output out1 = Output(8);
Output out2 = Output(9, true, "Output2");
Execute ex1;
void setup()
{
enc1.setDivider(4, RISING);
inp1.SetDebounceTime(200);
Serial.begin(9600);
}
void loop()
{
enc1.Read();
inp1.Read();
inp2.Read();
if(inp1.State())
{
Serial.println("inp1 state is HIGH");
}
out1.On();
out2.Off();
out1.Switch();
if(enc1.IfTriggered())
{
Serial.println("Triggered");
}
if(inp1.IfRising())
{
Serial.println("inp1 rising edge");
}
if(inp1.IfFalling())
{
Serial.println("inp1 falling edge");
}
if(inp2.Edge() == RISING)
{
Serial.println("inp1 rising edge");
}
if(inp2.Edge() == FALLING)
{
Serial.println("inp1 falling edge");
}
if(inp2.IfRising())
{
Serial.print(" LastRisingEdgeTime: ");
Serial.print(inp1.LastRisingEdgeTime());
Serial.print(" LastFallingEdgeTime: ");
Serial.println(inp1.LastFallingEdgeTime());
Serial.print("OnFor: ");
Serial.print(inp1.OnFor());
Serial.print(" ,OffFor ");
Serial.println(inp1.OffFor());
}
if(inp1.StateDiff())
{
ex1.InMillis(1000);
}
if(enc1.IfTriggered())
{
out1.OnForMillis(1000);
out2.OffForMillis(1000);
}
if(ex1.Check())
{
out1.OnForMillis(1000);
}
out1.Update(); // update when output uses (On/Off)for(Millis/Micros)
out2.Update();
enc1.Update(); // Update input when IfTriggered is used
}
The constructor defines an input object
Input(const int pin)
Input(const int pin, const String name)
**pin: ** Arduino pin number that the input is connected to (byte)
**name: ** Name of input used for debugging
#include <Input.h>
Input inp1 = Input(3);
Input inp1 = Input(3, "inp1");
The constructor defines an output object
Output(const int pin)
Output(const int pin, bool debug)
Output(const int pin, bool debug, const String name)
**pin: ** Arduino pin number that the output is connected to (byte)
**debug: ** If true, prints on serial all usefull information when testing **name: ** Name of output used for debugging
#include <Output.h>
Output out1 = Output(7);
Output out1 = Output(8, "Output1");
Output out2 = Output(9, true, "Output2");
The constructor defines an execute object
Execute()
#include <Execute.h>
Execute ex1;
Execute ex2();
Function used to set divider. When not set, the default value is 1. The divider tells how many state changes must appear for IfTriggered to be true.
inp1.setDivider(int divider, const int edgeType);
** divider: ** How many state changes there
** edgeType: ** ( CHANGE, RISING, FALLING ), count only on rising/falling edges. Default ( CHANGE ) - count on every state change
None.
void setup() {
inp1.setDivider(4);
inp2.setDivider(10, RISING);
inp3.setDivider(16, FALLING);
}
Sets debounce time for input. If function not used there is no debounce.
inp1.SetDebounceTime(unsigned long debounce_time)
** debounce_time: ** Debounce time in ms
None.
void setup() {
// Debounce time in ms
inp1.SetDebounceTime(200);
}
Reads the input state and more. Adds to counter, checks debounce times and falling/rising times.
None.
enc1.Read();
inp1.Read();
Get current state
Returns (bool) true or false
if(inp1.State()) {
Serial.println("Input is HIGH");
}
Check if last state is different that current state
Returns true if state != last_state or false state == last_state
if(inp1.StateDiff()) {
Serial.println("Input changed state");
}
Resets times and divider counter.
None.
inp1.Reset();
Check divider_counter >= divider
Returns true if divider_counter >= divider and resets divider_counter
if(inp1.IfTriggered()) {
Serial.println("Input just triggered");
}
If function IfTriggered is being used. Update() should be necessary at end of loop.
None.
inp1.Update();
Check if input just changed from LOW to HIGH or from HIGH to LOW
Returns true if and Edge has appeared (Rising or Falling)
if(inp1.IfRising()) {
Serial.println("Input had an rising edge");
}
if(inp1.IfFalling()) {
Serial.println("Input had an falling edge");
}
Prints useful information to Serial for debugging purposes
None.
inp1.Print();