-
Notifications
You must be signed in to change notification settings - Fork 0
/
LED-Matrix-Display.ino
135 lines (97 loc) · 2.38 KB
/
LED-Matrix-Display.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#include "Arduino.h"
#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>
#include <RF24.h>
String words[] = {"Hello", "World"};
#define switch1 6
#define switch2 5
#define switch3 4
RF24 radio(10, 9); // CE, CSN
const int RFaddress = 0x001;
// Define the number of devices we have in the chain and the hardware interface
// NOTE: These pin numbers will probably not work with your hardware and may
// need to be adapted
#define HARDWARE_TYPE MD_MAX72XX::PAROLA_HW
#define MAX_DEVICES 3
#define CLK_PIN 13
#define DATA_PIN 11
#define CS_PIN 8
// Hardware SPI connection
MD_Parola matrix = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
// Arbitrary output pins
// MD_Parola P = MD_Parola(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);
uint32_t startTime;
uint32_t time;
String inData;
void setup()
{
Serial.begin(9600);
pinMode(switch1, INPUT_PULLUP);
pinMode(switch2, INPUT_PULLUP);
pinMode(switch3, INPUT_PULLUP);
matrix.begin(1);
matrix.setTextAlignment(PA_CENTER);
matrix.setSpeed(0);
matrix.setPause(0);
matrix.setTextEffect(PA_PRINT, PA_NO_EFFECT);
matrix.setZoneEffect(0, true, PA_FLIP_LR);
radio.begin();
radio.openReadingPipe(0, RFaddress);
radio.setPALevel(RF24_PA_MIN);
radio.startListening();
String y = "";
for (int x = 0; x < MAX_DEVICES; x++){
y += x+1;
matrix.print(y);
delay(300);
}
delay(1000);
matrix.print("");
startTime = millis();
}
// TODO improve to byte instead of int ?
int readSwitches(){
int mode = 0;
if (digitalRead(switch1) == LOW)
{
mode += 1;
}
if (digitalRead(switch2) == LOW)
{
mode += 2;
}
if (digitalRead(switch3) == LOW){
mode += 4;
}
return mode;
}
// Cycle through functions VV
void loop()
{
if (readSwitches() == 0){
if (radio.available()) {
char text[99] = "";
radio.read(&text, sizeof(text));
Serial.println(text);
matrix.print(text);
}
}
else if (readSwitches() == 1){
if (Serial.available()){
inData = Serial.readStringUntil('\n');
Serial.println("\nPrinting: " + inData);
matrix.print(inData.substring(0,inData.length() - 1) );
}
}
else if(readSwitches() == 2){
for(int x = 0; x < 2; x++){
matrix.print(words[x]);
delay(4000);
}
}
else if (readSwitches() == 3){
time = round((millis() - startTime) / 1000);
matrix.print(time);
}
}