Paso 2: Código de prueba
#include < SPI.h >#define STATUS_PIN 9
#define CS_PIN 10
#define MOSI_PIN 12
#define MISO_PIN 11
#define SCK_PIN 13
#define SPI_MODE SPI_MODE1
#ifdef PCDUINO_IDE
#define SpiExchangeByte(x) SPI.transfer(x,SPI_CONTINUE)
#else
#define SpiExchangeByte(x) SPI.transfer(x)
#endif
void SetDefaultTask (char tarea, repeatTime largo)
{
bool DeviceStatus;
recuento corto sin firmar;
DeviceStatus = digitalRead(STATUS_PIN);
digitalWrite(CS_PIN,LOW);
SpiExchangeByte(2);
while(digitalRead(STATUS_PIN) == DeviceStatus);
DeviceStatus =! DeviceStatus;
SpiExchangeByte (tarea); //X
while(digitalRead(STATUS_PIN) == DeviceStatus);
DeviceStatus =! DeviceStatus;
SpiExchangeByte (0); //Y
while(digitalRead(STATUS_PIN) == DeviceStatus);
DeviceStatus =! DeviceStatus;
SpiExchangeByte (0); //Z
while(digitalRead(STATUS_PIN) == DeviceStatus);
DeviceStatus =! DeviceStatus;
SpiExchangeByte(repeatTime & 0xff); //R
while(digitalRead(STATUS_PIN) == DeviceStatus);
DeviceStatus =! DeviceStatus;
SpiExchangeByte ((repeatTime >> 8) & 0xff); //G
while(digitalRead(STATUS_PIN) == DeviceStatus);
DeviceStatus =! DeviceStatus;
SpiExchangeByte ((repeatTime >> 16) & 0xff); //B
while(digitalRead(STATUS_PIN) == DeviceStatus);
DeviceStatus =! DeviceStatus;
SpiExchangeByte ((repeatTime >> 24) & 0xff); //RSV
while(digitalRead(STATUS_PIN) == DeviceStatus);
digitalWrite(CS_PIN,HIGH);
}
void SetLedCubeColor(long color)
{
bool DeviceStatus;
recuento corto sin firmar;
DeviceStatus = digitalRead(STATUS_PIN);
digitalWrite(CS_PIN,LOW);
SpiExchangeByte(1);
while(digitalRead(STATUS_PIN) == DeviceStatus);
DeviceStatus =! DeviceStatus;
SpiExchangeByte (0); //X
while(digitalRead(STATUS_PIN) == DeviceStatus);
DeviceStatus =! DeviceStatus;
SpiExchangeByte (0); //Y
while(digitalRead(STATUS_PIN) == DeviceStatus);
DeviceStatus =! DeviceStatus;
SpiExchangeByte (0); //Z
while(digitalRead(STATUS_PIN) == DeviceStatus);
DeviceStatus =! DeviceStatus;
SpiExchangeByte (color & 0xff); //R
while(digitalRead(STATUS_PIN) == DeviceStatus);
DeviceStatus =! DeviceStatus;
SpiExchangeByte ((color >> 8) & 0xff); //G
while(digitalRead(STATUS_PIN) == DeviceStatus);
DeviceStatus =! DeviceStatus;
SpiExchangeByte ((color >> 16) & 0xff); //B
while(digitalRead(STATUS_PIN) == DeviceStatus);
DeviceStatus =! DeviceStatus;
SpiExchangeByte ((color >> 24) & 0xff); //RSV
while(digitalRead(STATUS_PIN) == DeviceStatus);
digitalWrite(CS_PIN,HIGH);
}
void SetPonitColor (char x, char y, char z, mucho color)
{
bool DeviceStatus;
recuento corto sin firmar;
DeviceStatus = digitalRead(STATUS_PIN);
digitalWrite(CS_PIN,LOW);
SpiExchangeByte(3);
while(digitalRead(STATUS_PIN) == DeviceStatus);
DeviceStatus =! DeviceStatus;
SpiExchangeByte (x); //X
while(digitalRead(STATUS_PIN) == DeviceStatus);
DeviceStatus =! DeviceStatus;
SpiExchangeByte (y); //Y
while(digitalRead(STATUS_PIN) == DeviceStatus);
DeviceStatus =! DeviceStatus;
SpiExchangeByte (z); //Z
while(digitalRead(STATUS_PIN) == DeviceStatus);
DeviceStatus =! DeviceStatus;
SpiExchangeByte (color & 0xff); //R
while(digitalRead(STATUS_PIN) == DeviceStatus);
DeviceStatus =! DeviceStatus;
SpiExchangeByte ((color >> 8) & 0xff); //G
while(digitalRead(STATUS_PIN) == DeviceStatus);
DeviceStatus =! DeviceStatus;
SpiExchangeByte ((color >> 16) & 0xff); //B
while(digitalRead(STATUS_PIN) == DeviceStatus);
DeviceStatus =! DeviceStatus;
SpiExchangeByte ((color >> 24) & 0xff); //RSV
while(digitalRead(STATUS_PIN) == DeviceStatus);
digitalWrite(CS_PIN,HIGH);
}
void SendImageData(void)
{
tmpShort corto sin firmar;
bool DeviceStatus;
recuento corto sin firmar;
DeviceStatus = digitalRead(STATUS_PIN);
digitalWrite(CS_PIN,LOW);
SpiExchangeByte(4);
while(digitalRead(STATUS_PIN) == DeviceStatus);
DeviceStatus =! DeviceStatus;
SpiExchangeByte (0); //X
while(digitalRead(STATUS_PIN) == DeviceStatus);
DeviceStatus =! DeviceStatus;
SpiExchangeByte (0); //Y
while(digitalRead(STATUS_PIN) == DeviceStatus);
DeviceStatus =! DeviceStatus;
SpiExchangeByte (0); //Z
while(digitalRead(STATUS_PIN) == DeviceStatus);
DeviceStatus =! DeviceStatus;
SpiExchangeByte (0); //R
while(digitalRead(STATUS_PIN) == DeviceStatus);
DeviceStatus =! DeviceStatus;
SpiExchangeByte (0); //G
while(digitalRead(STATUS_PIN) == DeviceStatus);
DeviceStatus =! DeviceStatus;
SpiExchangeByte (0); //B
while(digitalRead(STATUS_PIN) == DeviceStatus);
DeviceStatus =! DeviceStatus;
SpiExchangeByte (0); //RSV
while(digitalRead(STATUS_PIN) == DeviceStatus);
DeviceStatus =! DeviceStatus;
para (tmpShort = 0; tmpShort < 512 * 3; tmpShort ++)
{
SpiExchangeByte((char)tmpShort);
while(digitalRead(STATUS_PIN) == DeviceStatus);
DeviceStatus =! DeviceStatus;
}
digitalWrite(CS_PIN,HIGH);
}
void setup() {}
Pon tu código de instalación, para ejecutar una vez:
pinMode (STATUS_PIN, entrada);
pinMode (CS_PIN, salida);
pinMode (MOSI_PIN, salida);
pinMode (MISO_PIN, entrada);
pinMode (SCK_PIN, salida);
digitalWrite(CS_PIN,HIGH);
digitalWrite(STATUS_PIN,HIGH);
digitalWrite(SCK_PIN,LOW);
SPI.begin();
SPI.setBitOrder(MSBFIRST);
SPI.setDataMode(SPI_MODE);
SPI.setClockDivider(SPI_CLOCK_DIV4);
SetDefaultTask(0,15);
SetLedCubeColor(0x00000000);
SendImageData();
Delay(5000);
}
void loop() {}
Pon tu código principal, para ejecutar varias veces:
printf("SetLedCubeColor(R);\n");
SetLedCubeColor(0x00ff0000);
Delay(1000);
printf("SetLedCubeColor(G);\n");
SetLedCubeColor(0x0000ff00);
Delay(1000);
printf("SetLedCubeColor(B);\n");
SetLedCubeColor(0x000000ff);
Delay(1000);
printf("SetDefaultTask(1);\n");
SetDefaultTask(1,20);
Delay(5000);
printf("SetDefaultTask(2);\n");
SetDefaultTask(2,15);
Delay(5000);
printf("SetDefaultTask(3);\n");
SetDefaultTask(3,15);
Delay(5000);
}