-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLED.ino
50 lines (38 loc) · 912 Bytes
/
LED.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
#include <Wire.h>
#define ANODES 7
#define CATODES 5
const int ledAnodes[ANODES] = {2, 3, 4, 5, 6, 7, 8}; // LOW
const int ledCatodes[CATODES] = {9, 10, 11, 12, A0}; // HIGH
void setup() {
Wire.begin();
Wire.begin(8);
Wire.onReceive(receiveEvent);
Serial.begin(9600);
// LED Anodes
for (int i = 0; i < ANODES; i++) {
pinMode(ledAnodes[i], OUTPUT);
digitalWrite(ledAnodes[i], HIGH);
}
// LED Catodes
for (int i = 0; i < CATODES; i++) {
pinMode(ledCatodes[i], OUTPUT);
digitalWrite(ledCatodes[i], LOW);
}
}
void loop() {
}
void receiveEvent(int howMany) {
int catode;
int anode;
while (1 <= Wire.available()) {
catode = Wire.read();
anode = Wire.read();
}
digitalWrite(anode, LOW);
digitalWrite(catode, HIGH);
digitalWrite(anode, HIGH);
digitalWrite(catode, LOW);
Serial.print(catode);
Serial.print(" - ");
Serial.println(anode);
}