This library allows to transform the digital and analogue ports into objects and to allow in a simpler way to work with PWM, bouncing effect, standardized method of reading and writing, independent if the ports is digital or analogic.
Available methods:
void setToDigital(); // Somente se quiser usar uma porta analogica como digital void setMode(byte); // (0) INPUT, (1) OUTPUT, (2) INPUT_PULLUP void setDebounceDelay(unsigned long); // Tempo de debounce. O padrão é 50 ms int read(); // digitalRead |LOW|HIGH|FALLING|RISING| ou analogRead 0 - 500 byte readWithDebounce(); // digitalRead com debounce |LOW|HIGH|FALLING|RISING| unsigned long readTimeRunningLevel(); int readPulseCount(); void write(bool); // digitalWrite 0 ou 1 void writePwm(int); // analogWrite 0 - 500 void resetPulse();
#include <Pin.h>
#define pinLed1 3 #define pinLed2 5 #define pinLed3 6 #define pinBotao1 8 #define pinBotao2 9 #define pinBotao3 10 #define pinBotao4 A1
Pin led1(pinLed1); Pin led2(pinLed2); Pin led3(pinLed3); Pin botao1(pinBotao1); Pin botao2(pinBotao2); Pin botao3(pinBotao3); Pin botao4(pinBotao4); // Poteciometro
void setup(){ Serial.begin(115200);
led1.setMode(OUTPUT); led2.setMode(OUTPUT); led3.setMode(OUTPUT);
botao1.setMode(INPUT_PULLUP); botao2.setMode(INPUT_PULLUP); botao3.setMode(INPUT_PULLUP); botao4.setMode(INPUT);
led1.write(HIGH); led2.write(HIGH); }
void loop(){ led1.writePwm(100); led2.writePwm(500); delay(200); led1.writePwm(500); led2.writePwm(100);
Serial.print("read: "); Serial.println(botao1.read()); Serial.print("readWithDebounce: "); Serial.println(botao1.readWithDebounce());
botao1.readWithDebounce();
if(botao1.readWithDebounce() == FALLING){ Serial.print("readWithDebounce: "); Serial.print("FALLING"); }
delay(200); led1.writePwm(botao4.read()); Serial.println(botao4.read()); }
For more information about this library please visit us at https://github.com/silviogarbes/Arduino-Pin
Copyright (c) 2010 Arduino LLC. All right reserved.
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA