-
Notifications
You must be signed in to change notification settings - Fork 6
/
74HC165-HSPI+Intrrupt.ino
69 lines (54 loc) · 1.64 KB
/
74HC165-HSPI+Intrrupt.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/* 74HC165 ESP8266 ~ NodeMCU 1.0 (ESP-12E Module)
* speed-test reading 18 shift (in) registers
*
* adapted from article by João Alves
* https://jpralves.net/post/2015/09/08/multiple-inputs-parallel-to-series.html
*
* Pinos usados:
D0 (gpio16) - Load Pin (1) do 74HC165
D1 (gpio5) - Interrupt Pin do Diodes
D6 (hmiso) - Q7 Pin (9) do 74HC165
D5 (hsclk) - CLOCK Pin (2) do 74HC165
* Sketch que usa a comunicação SPI + interrumpir.
*/
#include <SPI.h>
const byte LATCH = D0;
const byte INTER = D1;
const byte chips = 18; // number of 74HC165 (8bit) chips used
static unsigned long lastMillis;
static unsigned long frameCount;
static unsigned int framesPerSecond;
const int seconds = 1;
// FIXME: finish interrupt support ...
void setup() {
SPI.begin ();
SPI.beginTransaction(SPISettings(32000000, MSBFIRST, SPI_MODE3)); // 32MHz
Serial.begin(230400);
pinMode (LATCH, OUTPUT);
digitalWrite (LATCH, HIGH);
}
void loop() {
unsigned long now = millis();
frameCount ++; // Once around the moon ...
byte Switch[chips];
digitalWrite (LATCH, LOW);
digitalWrite (LATCH, HIGH);
for (byte i=0; i<chips; i++) {
Switch[i] = SPI.transfer(0);
}
if (now - lastMillis >= seconds * 1000) {
framesPerSecond = frameCount / seconds;
for (byte i=0; i<8; i++) {
Serial.print((Switch[0] & (1<<i)) != 0 ? 0 : 1);
}
Serial.print(" ");
for (byte i=0; i<8; i++) {
Serial.print((Switch[1] & (1<<i)) != 0 ? 0 : 1);
}
Serial.print(" ");
Serial.print(framesPerSecond);
Serial.println(" fps");
frameCount = 0;
lastMillis = now;
}
}