Only pins 3,5 and 6 are PWM and will then drive the dimming of the LEDs.
Transfer immediately to sketck:
01
02
03
04
05
06
07
08
09
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
| #include "Ethernet.h" #include "OSCClass.h" #include "SPI.h" int pinLedA = 2; int pinLedB = 3; int pinLedC = 4; int pinLedD = 5; int pinLedE = 6; int pinLedF = 7; OSCMessage recMes; OSCClass OSC (& recMes); serverMac byte [] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; serverIP byte [] = {192, 168, 2, 130}; int serverPort = 10000; char * topAddress = "butt" ; char *subAddress[15]={ "ledA" , "ledB" , "ledC" , "ledD" , "ledE" , "ledF" , "ledAB" , "ledBC" , "ledAC" , "ledDE" , "ledEF" , "ledDF" , "fadeB" , "fadeD" , "fadeE" }; void setup () { Ethernet.begin (serverMac, serverIP); osc.begin (serverPort); pinMode (pinLedA, OUTPUT); pinMode (pinLedB, OUTPUT); pinMode (pinLedC, OUTPUT); pinMode (pinLedD, OUTPUT); pinMode (pinLedE, OUTPUT); pinMode (pinLedF, OUTPUT); digitalWrite (pinLedA, LOW); // LED OFF digitalWrite (pinLedB, LOW); // LED OFF digitalWrite (pinLedC, LOW); // LED OFF digitalWrite (pinLedD, LOW); // LED OFF digitalWrite (pinLedE, LOW); // LED OFF digitalWrite (pinLedF, LOW); // LED OFF osc.flush (); } void loop () { if (osc.available ()) { if (! strcmp (recMes.getAddress (0), topAddress)) { if (! strcmp (recMes.getAddress (1) Sub Address [0])) {digitalWrite (pinLedA, getIntValue (& recMes)); } if (! strcmp (recMes.getAddress (1), subaddress [1])) {digitalWrite (pinLedB, getIntValue (& recMes)); } if (! strcmp (recMes.getAddress (1), subaddress [2])) {digitalWrite (pinLedC, getIntValue (& recMes)); } if (! strcmp (recMes.getAddress (1), subaddress [3])) {digitalWrite (pinLedD, getIntValue (& recMes)); } if (! strcmp (recMes.getAddress (1), subaddress [4])) {digitalWrite (pinLedE, getIntValue (& recMes)); } if (! strcmp (recMes.getAddress (1), subaddress [5])) {digitalWrite (pinLedF, getIntValue (& recMes)); } if (! strcmp (recMes.getAddress (1), subaddress [6])) {digitalWrite (pinLedA, getIntValue (& recMes)); digitalWrite (pinLedB, getIntValue (& recMes)); } if (! strcmp (recMes.getAddress (1), subaddress [7])) {digitalWrite (pinLedB, getIntValue (& recMes)); digitalWrite (pinLedC, getIntValue (& recMes)); } if (! strcmp (recMes.getAddress (1), subaddress [8])) {digitalWrite (pinLedA, getIntValue (& recMes)); digitalWrite (pinLedC, getIntValue (& recMes)); } if (! strcmp (recMes.getAddress (1), subaddress [9])) {digitalWrite (pinLedD, getIntValue (& recMes)); digitalWrite (pinLedE, getIntValue (& recMes)); } if (! strcmp (recMes.getAddress (1), subaddress [10])) {digitalWrite (pinLedE, getIntValue (& recMes)); digitalWrite (pinLedF, getIntValue (& recMes)); } if (! strcmp (recMes.getAddress (1), subaddress [11])) {digitalWrite (pinLedD, getIntValue (& recMes)); digitalWrite (pinLedF, getIntValue (& recMes)); } if (! strcmp (recMes.getAddress (1), subaddress [12])) {analogWrite (pinLedB, getIntValue (& recMes)); } if (! strcmp (recMes.getAddress (1), subaddress [13])) {analogWrite (pinLedD, getIntValue (& recMes)); } if (! strcmp (recMes.getAddress (1), subaddress [14])) {analogWrite (pinLedE, getIntValue (& recMes)); } } } } // Utility *********************************** ********* int getIntValue (OSCMessage mes *) { switch (mes-> getTypeTag (0)) { case 'i' { return mes-> getArgInt (0); } break ; case 'f' { return int (mes-> getArgFloat (0)); } break ; } }
In the first lines include the classes that you will use for Ethernet communication and protocol handling OSC, using classes in Arduino allows you to concentrate mainly on functionality not worrying about the complexities of such a protocol.
lines 05-10: Define the pins that connect the LEDs, remember that the pins 10,11,12 and 13 are dedicated to communication with the Ethernet Shield;
|
Post a Comment