mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
0.1.1 refactor & testing
This commit is contained in:
parent
65f3ec50f4
commit
490f7ad6e3
21
libraries/PinInGroup/LICENSE
Normal file
21
libraries/PinInGroup/LICENSE
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2017-2020 Rob Tillaart
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
@ -1,57 +1,59 @@
|
|||||||
//
|
//
|
||||||
// FILE: PinInGroup.cpp
|
// FILE: PinInGroup.cpp
|
||||||
// AUTHOR: Rob Tillaart
|
// AUTHOR: Rob Tillaart
|
||||||
// VERSION: 0.1.0
|
// VERSION: 0.1.1
|
||||||
// DATE: 2017-04-26
|
// DATE: 2017-04-26
|
||||||
// PURPOSE: PinInGroup library for Arduino
|
// PURPOSE: PinInGroup library for Arduino
|
||||||
// goal is to easily change a group of pins that logically
|
// goal is to easily read a group of pins that logically
|
||||||
// belong to each other.
|
// belong to each other.
|
||||||
// The pins can be in any order.
|
// The pins can be in any order.
|
||||||
// URL: http://forum.arduino.cc/index.php?topic=469599.0
|
// URL: https://github.com/RobTillaart/PinInGroup
|
||||||
|
// http://forum.arduino.cc/index.php?topic=469599.0
|
||||||
//
|
//
|
||||||
// Released to the public domain
|
// 0.1.0 2017-08-20 initial version (based upon pinGroup)
|
||||||
//
|
// 0.1.1 2020-05-19 refactor; added clear(); added param for INPUT or INPUT_PULLUP
|
||||||
// 0.1.0 - initial version (based upon pinGroup)
|
|
||||||
//
|
|
||||||
|
|
||||||
#include "PinInGroup.h"
|
#include "PinInGroup.h"
|
||||||
|
|
||||||
PinInGroup::PinInGroup()
|
PinInGroup::PinInGroup()
|
||||||
|
{
|
||||||
|
clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void PinInGroup::clear()
|
||||||
{
|
{
|
||||||
_size = 0;
|
_size = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PinInGroup::add(uint8_t size, int* ar)
|
uint8_t PinInGroup::add(uint8_t sz, uint8_t * ar, uint8_t value)
|
||||||
{
|
{
|
||||||
bool b = true;
|
int n = 0;
|
||||||
for (uint8_t i = 0; i < size; i++)
|
for (uint8_t i = 0; i < sz; i++)
|
||||||
{
|
{
|
||||||
b = b && add(ar[i]);
|
n += add(ar[i], value);
|
||||||
}
|
}
|
||||||
return b;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PinInGroup::add(uint8_t pin)
|
uint8_t PinInGroup::add(uint8_t pin, uint8_t value)
|
||||||
{
|
{
|
||||||
if (_size < PININGROUP_MAXSIZE)
|
if (_size >= PININGROUP_MAXSIZE) return 0;
|
||||||
{
|
_pins[_size] = pin;
|
||||||
_pins[_size] = pin;
|
pinMode(pin, value);
|
||||||
pinMode(pin, INPUT);
|
_size++;
|
||||||
_size++;
|
return 1;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t PinInGroup::read()
|
uint16_t PinInGroup::read()
|
||||||
{
|
{
|
||||||
uint16_t value = 0;
|
uint16_t value = 0;
|
||||||
|
uint16_t mask = 0x01;
|
||||||
for (uint8_t i = 0; i < _size; i++)
|
for (uint8_t i = 0; i < _size; i++)
|
||||||
{
|
{
|
||||||
value <<= 1;
|
if (digitalRead(_pins[i])) value |= mask;
|
||||||
value = value | (digitalRead(_pins[i]) > 0 ? 1: 0);
|
mask <<= 1;
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- END OF FILE ---
|
// --- END OF FILE ---
|
||||||
|
@ -1,41 +1,55 @@
|
|||||||
#ifndef PININGROUP_H
|
#pragma once
|
||||||
// FILE: PinInGroup.h
|
// FILE: PinInGroup.h
|
||||||
// AUTHOR: Rob dot Tillaart at gmail dot com
|
// AUTHOR: Rob dot Tillaart at gmail dot com
|
||||||
// VERSION: 0.1.0
|
// VERSION: 0.1.1
|
||||||
|
// DATE: 2017-04-26
|
||||||
// PURPOSE: PinInGroup library for Arduino
|
// PURPOSE: PinInGroup library for Arduino
|
||||||
// HISTORY: See PinInGroup.cpp
|
// HISTORY: See PinInGroup.cpp
|
||||||
//
|
//
|
||||||
// Released to the public domain
|
// Note: ESP32 has some dedicated IO pins that cannot be used in a group.
|
||||||
|
// FLASH: pin 6 - 11 (maybe more)
|
||||||
//
|
//
|
||||||
|
|
||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
|
|
||||||
#define PININGROUP_LIB_VERSION "0.1.0"
|
#define PININGROUP_LIB_VERSION "0.1.1"
|
||||||
#define PININGROUP_MAXSIZE 16
|
|
||||||
|
// smaller MAXSIZE will reduce memory footprint with ditto bytes.
|
||||||
|
#ifndef PININGROUP_MAXSIZE
|
||||||
|
#define PININGROUP_MAXSIZE 16
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
//
|
|
||||||
// a PinInGroup is a group of up to sixteen input pins that can be read
|
|
||||||
// by means of one read command and combined into one uint16_t.
|
|
||||||
//
|
|
||||||
class PinInGroup
|
class PinInGroup
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PinInGroup();
|
PinInGroup();
|
||||||
|
|
||||||
// adds a predefined array of pinnumbers to the PinInGroup
|
|
||||||
bool add(uint8_t s, int* ar);
|
|
||||||
// adds a single pin to the PinInGroup
|
|
||||||
bool add(uint8_t pin);
|
|
||||||
|
|
||||||
// read up to 8 pins "simultaneously" into one byte.
|
// enables one to reset the pinGroup and repopulate it
|
||||||
uint16_t read();
|
void clear();
|
||||||
|
|
||||||
// get the current size of the PinInGroup.
|
// adds a predefined array of pin numbers to the PinInGroup
|
||||||
uint8_t size() { return _size; };
|
// sets all to either INPUT or INPUT_PULLUP.
|
||||||
// check how many free slots there are...
|
uint8_t add(uint8_t sz, uint8_t * ar, uint8_t value = INPUT);
|
||||||
uint8_t free() { return PININGROUP_MAXSIZE - _size; };
|
|
||||||
|
// adds a single pin to the PinInGroup
|
||||||
private:
|
uint8_t add(uint8_t pin, uint8_t value = INPUT);
|
||||||
uint8_t _pins[PININGROUP_MAXSIZE]; // should be malloced dynamically
|
|
||||||
uint8_t _size = 0;
|
// read up to 16 pins "simultaneously" in one call.
|
||||||
|
uint16_t read();
|
||||||
|
|
||||||
|
uint8_t size() {
|
||||||
|
return _size;
|
||||||
|
};
|
||||||
|
|
||||||
|
// check how many free "slots" there are...
|
||||||
|
uint8_t free() {
|
||||||
|
return PININGROUP_MAXSIZE - _size;
|
||||||
|
};
|
||||||
|
|
||||||
|
private:
|
||||||
|
uint8_t _pins[PININGROUP_MAXSIZE];
|
||||||
|
uint8_t _size = 0;
|
||||||
};
|
};
|
||||||
#endif
|
|
||||||
|
// -- END OF FILE --
|
||||||
|
37
libraries/PinInGroup/README.md
Normal file
37
libraries/PinInGroup/README.md
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
# PinInGroup
|
||||||
|
|
||||||
|
Arduino library to group reading to 16 input pins in one command
|
||||||
|
|
||||||
|
# Description
|
||||||
|
|
||||||
|
A PinInGroup holds a number of input pins that can be read by means of a single **read()** command.
|
||||||
|
The PinInGroup makes it easier to work with a number of inputs that are a logical unit,
|
||||||
|
e.g. think of reading a parallel bus or read 4 lines from a matrix keyboard, or just
|
||||||
|
read an array of switches.
|
||||||
|
|
||||||
|
### Performace
|
||||||
|
|
||||||
|
The PinInGroup is not much more efficient as reading the pins in a loopyourself.
|
||||||
|
Hoewever it is less programming and gives clearer code.
|
||||||
|
|
||||||
|
There exist some ideas to optimize the low level reading e.g. only reading
|
||||||
|
the registers only once, or hold register and bit info per pin.
|
||||||
|
These ideas will be explored when time permits.
|
||||||
|
|
||||||
|
Note: The current ideas are platform specific.
|
||||||
|
|
||||||
|
### interface
|
||||||
|
|
||||||
|
**clear()** sets the size to zero so one can repopulate.
|
||||||
|
|
||||||
|
**add()** adds a predefined array of pins of a single pin to the group.
|
||||||
|
Note one can set a 2nd parameter mode to **INPUT**(default) or **INPUT_PULLUP**.
|
||||||
|
|
||||||
|
**read(value)** reads a 16 bits unsigned int from max 16 pins.
|
||||||
|
|
||||||
|
**size()** and **free()** give information about the group.
|
||||||
|
|
||||||
|
# Operation
|
||||||
|
|
||||||
|
See examples
|
||||||
|
|
@ -2,26 +2,34 @@
|
|||||||
// AUTHOR: Rob dot Tillaart at gmail dot com
|
// AUTHOR: Rob dot Tillaart at gmail dot com
|
||||||
// VERSION: 0.1.0
|
// VERSION: 0.1.0
|
||||||
// PURPOSE: demo PinInGroup library for Arduino
|
// PURPOSE: demo PinInGroup library for Arduino
|
||||||
// HISTORY: 20-08-2017
|
// HISTORY: 20-08-2017
|
||||||
//
|
//
|
||||||
// Released to the public domain
|
// Released to the public domain
|
||||||
//
|
//
|
||||||
|
|
||||||
#include "PinInGroup.h"
|
#include "PinInGroup.h"
|
||||||
|
|
||||||
int ar[4] = {2, 3, 4, 13};
|
uint8_t ar[4] = {2, 3, 4, 23};
|
||||||
|
uint8_t alt[] = {23, 22, 1, 3, 21, 19, 18, 5, 23, 22, 1, 3, 21, 19, 18, 5};
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
Serial.print("\nPININGROUP_LIB_VERSION: ");
|
Serial.println(__FILE__);
|
||||||
|
|
||||||
|
Serial.print(F("\nPININGROUP_LIB_VERSION: "));
|
||||||
Serial.println(PININGROUP_LIB_VERSION);
|
Serial.println(PININGROUP_LIB_VERSION);
|
||||||
|
Serial.println();
|
||||||
|
|
||||||
test0();
|
test0();
|
||||||
test1();
|
test1();
|
||||||
test2();
|
test2();
|
||||||
|
test3();
|
||||||
Serial.println("done...");
|
test4();
|
||||||
|
test5();
|
||||||
|
test6();
|
||||||
|
|
||||||
|
Serial.println(F("done..."));
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
@ -31,24 +39,38 @@ void loop()
|
|||||||
// TEST1 verifies and times basic working
|
// TEST1 verifies and times basic working
|
||||||
void test0()
|
void test0()
|
||||||
{
|
{
|
||||||
pinMode(2, INPUT);
|
Serial.println();
|
||||||
|
Serial.println(__FUNCTION__);
|
||||||
|
delay(20);
|
||||||
|
|
||||||
|
uint16_t n1 = 0;
|
||||||
|
|
||||||
uint32_t t1 = micros();
|
uint32_t t1 = micros();
|
||||||
digitalRead(2);
|
n1 = digitalRead(2) > 0;
|
||||||
digitalRead(2);
|
n1 <<= 1;
|
||||||
digitalRead(2);
|
n1 |= digitalRead(3) > 0;
|
||||||
digitalRead(2);
|
n1 <<= 1;
|
||||||
|
n1 |= digitalRead(4) > 0;
|
||||||
|
n1 <<= 1;
|
||||||
|
n1 |= digitalRead(13) > 0;
|
||||||
uint32_t t2 = micros();
|
uint32_t t2 = micros();
|
||||||
|
|
||||||
Serial.print("time: ");
|
Serial.print(F(" val: "));
|
||||||
|
Serial.println(n1, BIN);
|
||||||
|
Serial.print(F("time: "));
|
||||||
Serial.println(t2 - t1);
|
Serial.println(t2 - t1);
|
||||||
Serial.println("Test0 done...");
|
Serial.print(F("time: "));
|
||||||
|
Serial.println((1.0 * (t2 - t1)) / 4, 1);
|
||||||
|
Serial.println(F("Test0 done..."));
|
||||||
Serial.println();
|
Serial.println();
|
||||||
}
|
}
|
||||||
|
|
||||||
void test1()
|
void test1()
|
||||||
{
|
{
|
||||||
|
Serial.println();
|
||||||
|
Serial.println(__FUNCTION__);
|
||||||
uint16_t n1;
|
uint16_t n1;
|
||||||
|
|
||||||
PinInGroup PIG;
|
PinInGroup PIG;
|
||||||
PIG.add(2);
|
PIG.add(2);
|
||||||
PIG.add(4);
|
PIG.add(4);
|
||||||
@ -59,41 +81,230 @@ void test1()
|
|||||||
Serial.println(PIG.size());
|
Serial.println(PIG.size());
|
||||||
Serial.print("free: ");
|
Serial.print("free: ");
|
||||||
Serial.println(PIG.free());
|
Serial.println(PIG.free());
|
||||||
|
delay(20);
|
||||||
|
|
||||||
uint32_t t1 = micros();
|
uint32_t t1 = micros();
|
||||||
n1 = PIG.read();
|
n1 = PIG.read();
|
||||||
uint32_t t2 = micros();
|
uint32_t t2 = micros();
|
||||||
|
|
||||||
Serial.print(" val: ");
|
Serial.print(F(" val: "));
|
||||||
Serial.println(n1);
|
Serial.println(n1, BIN);
|
||||||
Serial.print("time: ");
|
Serial.print(F("time: "));
|
||||||
Serial.println(t2 - t1);
|
Serial.println(t2 - t1);
|
||||||
Serial.println("Test1 done...");
|
Serial.print(F("time: "));
|
||||||
|
Serial.println((1.0 * (t2 - t1)) / PIG.size(), 1);
|
||||||
|
Serial.println(F("Test1 done..."));
|
||||||
Serial.println();
|
Serial.println();
|
||||||
}
|
}
|
||||||
|
|
||||||
void test2()
|
void test2()
|
||||||
{
|
{
|
||||||
uint16_t n1;
|
Serial.println();
|
||||||
|
Serial.println(__FUNCTION__);
|
||||||
PinInGroup PIG;
|
|
||||||
for (int p=2; p<14; p++) PIG.add(p);
|
|
||||||
|
|
||||||
Serial.print("size: ");
|
uint16_t n1;
|
||||||
|
|
||||||
|
PinInGroup PIG;
|
||||||
|
|
||||||
|
#if defined(ESP32) || defined(ESP8266)
|
||||||
|
// be carefull which pins you use for ESP32 (and probably 8266 too, not tested)
|
||||||
|
// note: GPIO06 through GPIO11 are reserved for the FLASH.
|
||||||
|
// You cannot use them. ==> pinMode() fails.
|
||||||
|
// https://github.com/espressif/arduino-esp32/issues/1411
|
||||||
|
//
|
||||||
|
for (uint8_t p = 20; p < 36; p++) PIG.add(p);
|
||||||
|
#else
|
||||||
|
for (uint8_t p = 2; p < 14; p++) PIG.add(p);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
Serial.print(F("size: "));
|
||||||
Serial.println(PIG.size());
|
Serial.println(PIG.size());
|
||||||
Serial.print("free: ");
|
Serial.print(F("free: "));
|
||||||
Serial.println(PIG.free());
|
Serial.println(PIG.free());
|
||||||
|
delay(20);
|
||||||
|
|
||||||
uint32_t t1 = micros();
|
uint32_t t1 = micros();
|
||||||
n1 = PIG.read();
|
n1 = PIG.read();
|
||||||
uint32_t t2 = micros();
|
uint32_t t2 = micros();
|
||||||
|
|
||||||
Serial.print(" val: ");
|
Serial.print(F(" val: "));
|
||||||
Serial.println(n1);
|
Serial.println(n1, BIN);
|
||||||
Serial.print("time: ");
|
Serial.print(F("time: "));
|
||||||
Serial.println(t2 - t1);
|
Serial.println(t2 - t1);
|
||||||
Serial.println("Test1 done...");
|
Serial.print(F("time: "));
|
||||||
|
Serial.println((1.0 * (t2 - t1)) / PIG.size(), 1);
|
||||||
|
Serial.println(F("Test2 done..."));
|
||||||
Serial.println();
|
Serial.println();
|
||||||
}
|
}
|
||||||
|
|
||||||
// END OF FILE
|
void test3()
|
||||||
|
{
|
||||||
|
Serial.println();
|
||||||
|
Serial.println(__FUNCTION__);
|
||||||
|
|
||||||
|
uint16_t n1;
|
||||||
|
|
||||||
|
PinInGroup PIG;
|
||||||
|
PIG.add(4, ar, INPUT_PULLUP);
|
||||||
|
PIG.add(4, ar, INPUT_PULLUP);
|
||||||
|
PIG.add(4, ar, INPUT_PULLUP);
|
||||||
|
PIG.add(4, ar, INPUT_PULLUP);
|
||||||
|
|
||||||
|
Serial.print(F("size: "));
|
||||||
|
Serial.println(PIG.size());
|
||||||
|
Serial.print(F("free: "));
|
||||||
|
Serial.println(PIG.free());
|
||||||
|
|
||||||
|
PIG.add(4, ar, INPUT_PULLUP); // should not be added
|
||||||
|
|
||||||
|
Serial.print(F("size: "));
|
||||||
|
Serial.println(PIG.size());
|
||||||
|
Serial.print(F("free: "));
|
||||||
|
Serial.println(PIG.free());
|
||||||
|
Serial.println();
|
||||||
|
delay(20);
|
||||||
|
PIG.clear();
|
||||||
|
|
||||||
|
for (int i = 1; i <= 16; i++)
|
||||||
|
{
|
||||||
|
PIG.add(23);
|
||||||
|
uint32_t t1 = micros();
|
||||||
|
n1 = PIG.read();
|
||||||
|
uint32_t t2 = micros();
|
||||||
|
float timePerPin2 = (1.0 * t2 - t1) / i;
|
||||||
|
|
||||||
|
Serial.print(i);
|
||||||
|
Serial.print('\t');
|
||||||
|
Serial.print(t2 - t1);
|
||||||
|
Serial.print('\t');
|
||||||
|
Serial.print(timePerPin2);
|
||||||
|
Serial.print('\t');
|
||||||
|
Serial.println(n1, BIN);
|
||||||
|
delay(20);
|
||||||
|
}
|
||||||
|
|
||||||
|
Serial.println(F("Test3 done..."));
|
||||||
|
Serial.println();
|
||||||
|
}
|
||||||
|
|
||||||
|
void test4()
|
||||||
|
{
|
||||||
|
Serial.println();
|
||||||
|
Serial.println(__FUNCTION__);
|
||||||
|
|
||||||
|
uint16_t n1;
|
||||||
|
|
||||||
|
PinInGroup PIG;
|
||||||
|
PIG.add(4, ar, INPUT_PULLUP);
|
||||||
|
PIG.add(4, ar, INPUT_PULLUP);
|
||||||
|
PIG.add(4, ar, INPUT_PULLUP);
|
||||||
|
PIG.add(4, ar, INPUT_PULLUP);
|
||||||
|
|
||||||
|
Serial.print(F("size: "));
|
||||||
|
Serial.println(PIG.size());
|
||||||
|
Serial.print(F("free: "));
|
||||||
|
Serial.println(PIG.free());
|
||||||
|
|
||||||
|
PIG.clear();
|
||||||
|
PIG.add(4, ar, INPUT_PULLUP); // should not be added
|
||||||
|
|
||||||
|
Serial.print(F("size: "));
|
||||||
|
Serial.println(PIG.size());
|
||||||
|
Serial.print(F("free: "));
|
||||||
|
Serial.println(PIG.free());
|
||||||
|
delay(20);
|
||||||
|
|
||||||
|
uint32_t t1 = micros();
|
||||||
|
n1 = PIG.read();
|
||||||
|
uint32_t t2 = micros();
|
||||||
|
|
||||||
|
Serial.print(F(" val: "));
|
||||||
|
Serial.println(n1, BIN);
|
||||||
|
Serial.print(F("time: "));
|
||||||
|
Serial.println(t2 - t1);
|
||||||
|
Serial.print(F("time: "));
|
||||||
|
Serial.println((1.0 * (t2 - t1)) / PIG.size(), 1);
|
||||||
|
Serial.println(F("Test4 done..."));
|
||||||
|
Serial.println();
|
||||||
|
}
|
||||||
|
|
||||||
|
void test5()
|
||||||
|
{
|
||||||
|
Serial.println();
|
||||||
|
Serial.println(__FUNCTION__);
|
||||||
|
|
||||||
|
uint16_t n1 = 0;
|
||||||
|
|
||||||
|
uint32_t t1 = micros();
|
||||||
|
n1 = digitalRead(2) > 0;
|
||||||
|
n1 <<= 1;
|
||||||
|
n1 |= digitalRead(3) > 0;
|
||||||
|
n1 <<= 1;
|
||||||
|
n1 |= digitalRead(4) > 0;
|
||||||
|
n1 <<= 1;
|
||||||
|
n1 |= digitalRead(13) > 0;
|
||||||
|
uint32_t t2 = micros();
|
||||||
|
float timePerPin = (1.0 * t2 - t1) / 4;
|
||||||
|
|
||||||
|
Serial.print(F(" val: "));
|
||||||
|
Serial.println(n1, BIN);
|
||||||
|
Serial.print(F("time: "));
|
||||||
|
Serial.println(t2 - t1);
|
||||||
|
Serial.print(F("time: "));
|
||||||
|
Serial.println(timePerPin);
|
||||||
|
Serial.println();
|
||||||
|
|
||||||
|
PinInGroup PIG;
|
||||||
|
|
||||||
|
for (int i = 1; i <= 16; i++)
|
||||||
|
{
|
||||||
|
PIG.add(2);
|
||||||
|
t1 = micros();
|
||||||
|
n1 = PIG.read();
|
||||||
|
t2 = micros();
|
||||||
|
float timePerPin2 = (1.0 * t2 - t1) / i;
|
||||||
|
|
||||||
|
Serial.print(i);
|
||||||
|
Serial.print('\t');
|
||||||
|
Serial.print(t2 - t1);
|
||||||
|
Serial.print('\t');
|
||||||
|
Serial.print(timePerPin2);
|
||||||
|
Serial.print('\t');
|
||||||
|
Serial.println(timePerPin2 / timePerPin * 100.0);
|
||||||
|
delay(20);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Serial.println(F("Test5 done..."));
|
||||||
|
Serial.println();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void test6()
|
||||||
|
{
|
||||||
|
Serial.println();
|
||||||
|
Serial.println(__FUNCTION__);
|
||||||
|
|
||||||
|
uint16_t n1 = 0;
|
||||||
|
|
||||||
|
PinInGroup PIG;
|
||||||
|
|
||||||
|
// verify pin stays same place in output.
|
||||||
|
// connect selected pin to GND and it should stay on same spot.
|
||||||
|
// even when pins are added.
|
||||||
|
for (int i = 1; i <= 10; i++)
|
||||||
|
{
|
||||||
|
PIG.add(i, INPUT_PULLUP);
|
||||||
|
n1 = PIG.read() + 32768;
|
||||||
|
|
||||||
|
Serial.print(i);
|
||||||
|
Serial.print('\t');
|
||||||
|
Serial.print(n1, BIN);
|
||||||
|
Serial.print('\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
Serial.println(F("Test6 done..."));
|
||||||
|
Serial.println();
|
||||||
|
}
|
||||||
|
|
||||||
|
// -- END OF FILE --
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "PinInGroup",
|
"name": "PinInGroup",
|
||||||
"keywords": "PinInGroup,pin,group",
|
"keywords": "PinInGroup, pin, group, INPUT",
|
||||||
"description": "A class that groups input pins so they can be read in one logical step",
|
"description": "A class that groups input pins so they can be read in one logical step",
|
||||||
"authors":
|
"authors":
|
||||||
[
|
[
|
||||||
@ -13,12 +13,12 @@
|
|||||||
"repository":
|
"repository":
|
||||||
{
|
{
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/RobTillaart/Arduino.git"
|
"url": "https://github.com/RobTillaart/PinInGroup.git"
|
||||||
},
|
},
|
||||||
"version":"0.1.0",
|
"version":"0.1.1",
|
||||||
"frameworks": "arduino",
|
"frameworks": "arduino",
|
||||||
"platforms": "*",
|
"platforms": "*",
|
||||||
"export": {
|
"export": {
|
||||||
"include": "libraries/PinInGroup
|
"include": "PinInGroup
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
name=pinGroup
|
name=PinInGroup
|
||||||
version=0.1.0
|
version=0.1.1
|
||||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||||
sentence=A class that groups input pins so they can be read in one logical step.
|
sentence=A class that groups input pins so they can be read in one logical step.
|
||||||
paragraph=
|
paragraph=
|
||||||
category=Uncategorized
|
category=Communication
|
||||||
url=https://github.com/RobTillaart/Arduino/tree/master/libraries
|
url=https://github.com/RobTillaart/PinInGroup
|
||||||
architectures=*
|
architectures=*
|
||||||
|
includes=PinInGroup.h
|
||||||
|
depends=
|
||||||
|
Loading…
Reference in New Issue
Block a user