-
Notifications
You must be signed in to change notification settings - Fork 0
/
reading-TM1638-buttons-sample-code-1.txt
45 lines (39 loc) · 1.7 KB
/
reading-TM1638-buttons-sample-code-1.txt
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
//demonstration of button reads on the TM1638 LED & KEY board
const int strobePin = 8;
const int clockPin = 9;
const int dataPin = 10;
int keys1;
int keys2;
int keys3;
int keys4;
void setup()
{
Serial.begin(9600);
pinMode(strobePin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
digitalWrite(strobePin, LOW); //set the strobe low so it'll accept instruction
shiftOut(dataPin, clockPin, LSBFIRST, 0x8F); // activate and set brightness to max
digitalWrite(strobePin, HIGH);
}
void loop()
{
digitalWrite(strobePin, LOW); //set the strobe low so it'll accept instruction
shiftOut(dataPin, clockPin, LSBFIRST, 0x42); // activate and set brightness to max
pinMode(dataPin, INPUT_PULLUP); //Instruction received, board changes DIO to OUTPUT, we now need to set the pin as INPUT
keys1 = shiftIn(dataPin, clockPin, LSBFIRST); // read in first byte of data
keys2 = shiftIn(dataPin, clockPin, LSBFIRST); // read in first byte of data
keys3 = shiftIn(dataPin, clockPin, LSBFIRST); // read in first byte of data
keys4 = shiftIn(dataPin, clockPin, LSBFIRST); // read in first byte of data
Serial.print(" Byte 0:");
Serial.print(keys1);
Serial.print(" Byte 1:");
Serial.print(keys2);
Serial.print(" Byte 2:");
Serial.print(keys3);
Serial.print(" Byte 3:");
Serial.println(keys4);
digitalWrite(strobePin, HIGH); // all data is received, and just like any other instruction, the strobe line must go high when finished
pinMode(dataPin, OUTPUT); //having sent all data, the board now sets the DIO line as INPUT, we switch the arduino back to OUTPUT
delay(10); // just give the serial monitor a brief delay so we can read stuff
}