Skip to content

Commit 9abe150

Browse files
committed
update libraries M..P
1 parent de6544a commit 9abe150

File tree

93 files changed

+2878
-813
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+2878
-813
lines changed

libraries/NibbleArray/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2017-2020 Rob Tillaart
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

libraries/NibbleArray/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# nibbleArray
2+
3+
Arduino library for a compact array of nibbles (4 bit units)
4+
5+
## Description
6+
7+
A nibble is a 4 bit element, which can hold a value 0..15 (0..F in HEX).
8+
9+
The nibbleArray is an array that stores 2 nibbles in a byte therefor it is
10+
twice as small as a normal array.
11+
12+
The current implementation can hold 510 elements. This is due a limitation of
13+
the UNO which can alloc max 255 bytes in one **malloc()** call.
14+
15+
This **NIBBLEARRAY_MAXSIZE** can be defined compiletime "-D NIBBLEARRAY_MAXSIZE"
16+
or one can adjust it in the library if other platforms can allocate more memory.
17+
18+
## Interface
19+
20+
The interface of the nibbleArray is straightforward:
21+
22+
* **get(index)** idem
23+
* **set(index, value)** idem
24+
* **clear()** set all elements to 0;
25+
* **SetAll(value)** set all elements to value
26+
27+
## Operation
28+
29+
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
//
2+
// FILE: nibbleArray_demo.ino
3+
// AUTHOR: Rob Tillaart
4+
// VERSION: 0.1.0
5+
// PURPOSE: demo nibble array
6+
// DATE: 2020-06-21
7+
// URL: https://github.com/RobTillaart/nibbleArray
8+
9+
// 0.1.0 2020-06-21 initial version
10+
//
11+
#include "nibbleArray.h"
12+
13+
nibbleArray na(500);
14+
15+
void setup()
16+
{
17+
Serial.begin(115200);
18+
Serial.println(__FILE__);
19+
Serial.print("NIBBLEARRAY_LIB_VERSION: ");
20+
Serial.println(NIBBLEARRAY_LIB_VERSION);
21+
22+
test_1();
23+
24+
Serial.println("\nDone...");
25+
}
26+
27+
void test_1()
28+
{
29+
int ar[16];
30+
for (int i = 0; i < 16; i++) ar[i] = 0;
31+
32+
na.clear();
33+
34+
// 500 throws with 3 dices (3..18 ==> 0..15)
35+
for (int i = 0; i < 500; i++)
36+
{
37+
uint8_t sum = random(6);
38+
sum += random(6);
39+
sum += random(6);
40+
na.set(i, sum); // diff from na.set(i, random(16));
41+
}
42+
for (int i = 0; i < 500; i++)
43+
{
44+
ar[na.get(i)]++;
45+
Serial.print(" ");
46+
Serial.print(na.get(i), HEX);
47+
if ((i % 32) == 31) Serial.println();
48+
}
49+
Serial.println();
50+
Serial.println("\nFrequency analysis");
51+
for (int i = 0; i < 16; i++)
52+
{
53+
Serial.print(i);
54+
Serial.print("\t");
55+
// for (int p = 0; p < ar[i]; p++) Serial.print(">");
56+
Serial.print(ar[i]);
57+
Serial.println();
58+
}
59+
Serial.println();
60+
61+
Serial.println("\ninterpret data as a route");
62+
for (int i = 0; i < 20; )
63+
{
64+
uint8_t s = na.get(i++);
65+
uint8_t d = na.get(i++);
66+
move(s, d);
67+
}
68+
69+
Serial.println("\nor store music in the array");
70+
for (int i = 0; i < 30; )
71+
{
72+
uint8_t octave = na.get(i++);
73+
uint8_t note = na.get(i++);
74+
uint8_t duration = na.get(i++); // in 1/16th
75+
play(octave, note, duration);
76+
// sendMIDI(note, duration);
77+
}
78+
}
79+
80+
void play(uint8_t chord, uint8_t note, uint8_t duration)
81+
{
82+
Serial.print("Play: ");
83+
// Serial.print(chord);
84+
Serial.print(" ");
85+
switch (note)
86+
{
87+
case 0: Serial.print("C "); break;
88+
case 1: Serial.print("C# "); break;
89+
case 2: Serial.print("D "); break;
90+
case 3: Serial.print("D# "); break;
91+
case 4: Serial.print("E "); break;
92+
case 5: Serial.print("F "); break;
93+
case 6: Serial.print("F# "); break;
94+
case 7: Serial.print("G "); break;
95+
case 8: Serial.print("G# "); break;
96+
case 9: Serial.print("A "); break;
97+
case 10: Serial.print("A# "); break;
98+
case 11: Serial.print("B "); break;
99+
case 12: Serial.print("C "); break;
100+
case 13: Serial.print("C# "); break;
101+
case 14: Serial.print("D "); break;
102+
case 15: Serial.print(" - "); break;
103+
}
104+
for (uint8_t i = 0; i < duration; i++)
105+
{
106+
delay(1000 / 16);
107+
Serial.print(".");
108+
}
109+
Serial.println();
110+
}
111+
112+
113+
void move(uint8_t steps, uint8_t direction)
114+
{
115+
Serial.print(steps);
116+
Serial.print(" steps to the ");
117+
switch (direction)
118+
{
119+
case 0: Serial.print("N"); break;
120+
case 1: Serial.print("NNO"); break;
121+
case 2: Serial.print("NO"); break;
122+
case 3: Serial.print("ONO"); break;
123+
case 4: Serial.print("O"); break;
124+
case 5: Serial.print("OZO"); break;
125+
case 6: Serial.print("ZO"); break;
126+
case 7: Serial.print("ZZO"); break;
127+
case 8: Serial.print("Z"); break;
128+
case 9: Serial.print("ZZW"); break;
129+
case 10: Serial.print("ZW"); break;
130+
case 11: Serial.print("WZW"); break;
131+
case 12: Serial.print("W"); break;
132+
case 13: Serial.print("WNW"); break;
133+
case 14: Serial.print("NW"); break;
134+
case 15: Serial.print("NNW"); break;
135+
}
136+
Serial.println();
137+
delay(100 * steps);
138+
}
139+
140+
void loop()
141+
{
142+
}
143+
144+
// -- END OF FILE --
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
//
2+
// FILE: nibbleArray_performance.ino
3+
// AUTHOR: Rob Tillaart
4+
// VERSION: 0.1.0
5+
// PURPOSE: demo performance nibble array
6+
// DATE: 2020-06-21
7+
// URL: https://github.com/RobTillaart/nibbleArray
8+
9+
// 0.1.0 2020-06-21 initial version
10+
//
11+
#include "nibbleArray.h"
12+
13+
nibbleArray na(500);
14+
15+
uint32_t start, stop, d1, d2;
16+
volatile long x = 0;
17+
18+
void setup()
19+
{
20+
Serial.begin(115200);
21+
Serial.println(__FILE__);
22+
Serial.print("NIBBLEARRAY_LIB_VERSION: ");
23+
Serial.println(NIBBLEARRAY_LIB_VERSION);
24+
25+
// performance tests are run first once in a loop
26+
// then twice in a loop, so the difference is without
27+
// the loop overhead.
28+
test_size();
29+
test_get();
30+
test_set();
31+
test_clear();
32+
test_setAll();
33+
34+
Serial.println("Done...");
35+
}
36+
37+
void test_size()
38+
{
39+
Serial.print("Nibble array size:\t");
40+
Serial.println(na.size());
41+
delay(100);
42+
}
43+
44+
void test_get()
45+
{
46+
Serial.println("\nget");
47+
start = micros();
48+
for (int i = 0; i < 500; i++)
49+
{
50+
x += na.get(i);
51+
}
52+
stop = micros();
53+
Serial.print("DURATION:\t");
54+
d1 = stop - start;
55+
Serial.println(d1);
56+
delay(100);
57+
58+
start = micros();
59+
for (int i = 0; i < 500; i++)
60+
{
61+
x += na.get(i);
62+
x += na.get(i);
63+
}
64+
stop = micros();
65+
Serial.print("DURATION:\t");
66+
d2 = stop - start;
67+
Serial.println(d2);
68+
Serial.print("DELTA:\t\t");
69+
Serial.println(d2 - d1);
70+
Serial.print(" X:\t");
71+
Serial.println(x);
72+
delay(100);
73+
}
74+
75+
void test_set()
76+
{
77+
Serial.println("\nset");
78+
start = micros();
79+
for (int i = 0; i < 500; i++)
80+
{
81+
na.set(i, 5);
82+
}
83+
stop = micros();
84+
Serial.print("DURATION:\t");
85+
d1 = stop - start;
86+
Serial.println(d1);
87+
delay(100);
88+
89+
start = micros();
90+
for (int i = 0; i < 500; i++)
91+
{
92+
na.set(i, 5);
93+
na.set(i, 10);
94+
}
95+
stop = micros();
96+
Serial.print("DURATION:\t");
97+
d2 = stop - start;
98+
Serial.println(d2);
99+
Serial.print("DELTA:\t\t");
100+
Serial.println(d2 - d1);
101+
delay(100);
102+
}
103+
104+
void test_clear()
105+
{
106+
Serial.println("\nclear");
107+
start = micros();
108+
na.clear();
109+
stop = micros();
110+
Serial.print("DURATION:\t");
111+
d1 = stop - start;
112+
Serial.println(d1);
113+
delay(100);
114+
115+
start = micros();
116+
na.clear();
117+
na.clear();
118+
stop = micros();
119+
Serial.print("DURATION:\t");
120+
d2 = stop - start;
121+
Serial.println(d2);
122+
Serial.print("DELTA:\t\t");
123+
Serial.println(d2 - d1);
124+
delay(100);
125+
for (int i = 0; i < 500; i++)
126+
{
127+
if (na.get(i) != 0)
128+
{
129+
Serial.println("Error in clear");
130+
}
131+
}
132+
delay(100);
133+
}
134+
135+
void test_setAll()
136+
{
137+
Serial.println("\nsetAll");
138+
start = micros();
139+
na.setAll(1);
140+
stop = micros();
141+
Serial.print("DURATION:\t");
142+
d1 = stop - start;
143+
Serial.println(d1);
144+
delay(100);
145+
for (int i = 0; i < 500; i++)
146+
{
147+
if (na.get(i) != 1)
148+
{
149+
Serial.println("Error in setAll");
150+
}
151+
}
152+
delay(100);
153+
154+
start = micros();
155+
na.setAll(2);
156+
na.setAll(3);
157+
stop = micros();
158+
Serial.print("DURATION:\t");
159+
d2 = stop - start;
160+
Serial.println(d2);
161+
Serial.print("DELTA:\t\t");
162+
Serial.println(d2 - d1);
163+
delay(100);
164+
}
165+
166+
void loop()
167+
{
168+
}
169+
170+
// -- END OF FILE --

libraries/NibbleArray/library.json

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,9 @@
1313
"repository":
1414
{
1515
"type": "git",
16-
"url": "https://github.com/RobTillaart/Arduino.git"
16+
"url": "https://github.com/RobTillaart/nibbleArray.git"
1717
},
18-
"version":"0.1.0",
18+
"version":"0.2.0",
1919
"frameworks": "arduino",
20-
"platforms": "*",
21-
"export": {
22-
"include": "libraries/NibbleArray"
23-
}
20+
"platforms": "*"
2421
}
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
name=NibbleArray
2-
version=0.1.0
2+
version=0.2.0
33
author=Rob Tillaart <rob.tillaart@gmail.com>
44
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
55
sentence=Library to implement a compact array of nibbles (4 bit).
66
paragraph=
77
category=Data Processing
88
url=https://github.com/RobTillaart/Arduino/tree/master/libraries/
9-
architectures=*
9+
architectures=*
10+
includes=nibbleArray.h
11+
depends=

0 commit comments

Comments
 (0)