haha good point! i was wondering why nobody was responding. I was unsure if the two devices would be able to work together because they both use SPI. Posted below now is my code:
#include <Tlc5940.h>
#include <tlc_animations.h>
#include <tlc_config.h>
#include <tlc_fades.h>
#include <tlc_progmem_utils.h>
#include <tlc_servos.h>
#include <tlc_shifts.h>
#include <SPI.h>
#include <Ethernet.h>
#include <EthernetUdp.h>
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 1, 200);
unsigned int localPort = 8888; // local port to listen on
char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; //buffer to hold incoming packet,
EthernetUDP Udp;
int packetSize;
char Buffer[9];
char handshake;
char command_type;
char command_pin0;
char command_pin1;
char terminator;
int digit1;
int digit2;
int digit3;
int digit4;
int in_value;
int pin;
int val;
void setup()
{
Serial.begin(9600);
Ethernet.begin(mac,ip);
Udp.begin(localPort);
Tlc.init();
for (int i = 0; i<16; i = i+1)
{
Tlc.set(i,0);
Tlc.update();
delay(5);
}
}
void loop()
{
if (Serial.available()==9)
{
for (int m = 0; m<=8; m = m+1)
{
Buffer[m] = Serial.read();
}
command_serial();
}
else if(Serial.available()<9 || Serial.available()>9)
{
Serial.flush();
}
packetSize = Udp.parsePacket();
if(packetSize)
{
IPAddress remote = Udp.remoteIP();
Udp.read(packetBuffer,UDP_TX_PACKET_MAX_SIZE);
command_udp();
}
}
void command_udp()
{
handshake = packetBuffer[0];
command_type = packetBuffer[1];
command_pin0 = packetBuffer[2];
command_pin1 = packetBuffer[3];
digit1 = packetBuffer[4];
digit2 = packetBuffer[5];
digit3 = packetBuffer[6];
digit4 = packetBuffer[7];
terminator = packetBuffer[8];
}
void command_serial()
{
handshake = Buffer[0];
command_type = Buffer[1];
command_pin0 = Buffer[2];
command_pin1 = Buffer[3];
digit1 = Buffer[4];
digit2 = Buffer[5];
digit3 = Buffer[6];
digit4 = Buffer[7];
terminator = Buffer[8];
parsing();
}
void parsing()
{
digit1 = digit1-48;
digit1 = digit1*1000;
digit2 = digit2-48;
digit2 = digit2*100;
digit3 = digit3-48;
digit3 = digit3*10;
digit4 = digit4-48;
in_value = digit1+digit2+digit3+digit4;
command_pin0 = command_pin0 - 48;
command_pin1 = command_pin1 - 48;
command_pin0 = command_pin0 * 10;
pin = command_pin0+command_pin1;
if (handshake == '!' && terminator == '@' && in_value <= 4095)
{
switch (command_type)
{
case 'A':
Tlc.set(pin,in_value);
Tlc.update();
Serial.print("1");
delay(5);
break;
case 'a':
val = analogRead(pin);
Serial.print("1");
break;
case 'D':
if (in_value == 4095) { digitalWrite(pin, HIGH);}
if (in_value ==0) { digitalWrite(pin, LOW);}
Serial.print("1");
break;
case 'd':
val = digitalRead(pin);
Serial.print("1");
break;
case 'P':
pinMode(pin,OUTPUT);
Serial.print("1");
break;
case 'p':
pinMode(pin,INPUT);
Serial.print("1");
break;
default:
break;
}
}
}