rainbow:
#include <stdio.h>
#include <avr/pgmspace.h>
// ############################ Befehlsstruktur definieren ###############################
#ifndef WireCommands_h
#define WireCommands_h
#define MAX_WIRE_CMD 0x80
#define CMD_NOP 0x00
#define CMD_SWAP_BUF 0x10
#define CMD_COPY_FRONT_BUF 0x11
#define CMD_SHOW_AUX_BUF 0x12
#define CMD_CLEAR_BUF 0x20
#define CMD_SET_PAPER 0x21
#define CMD_SET_INK 0x22
#define CMD_CLEAR_PAPER 0x25
#define CMD_DRAW_PIXEL 0x26
#define CMD_DRAW_LINE 0x27
#define CMD_DRAW_SQUARE 0x28
#define CMD_PRINT_CHAR 0x2A
#define CMD_DRAW_ROW_MASK 0x2B
extern unsigned char CMD_totalArgs[MAX_WIRE_CMD];
#endif
// ################### Argumentenanzahl für jeden Befehl speichern #######################
unsigned char CMD_totalArgs[MAX_WIRE_CMD] PROGMEM = {
// 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - A - B - C - D - E - F
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0 - 0x00 -> 0x0F
0, 2, 1, 2, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, // 1 - 0x10 -> 0x1F
3, 3, 3, 0, 0, 0, 2, 4, 4, 0, 3, 3, 0, 0, 0, 0, // 2 - 0x00 -> 0x2F
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 3 - 0x00 -> 0x3F
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 4 - 0x00 -> 0x4F
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 5 - 0x50 -> 0x5F
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 6 - 0x60 -> 0x6F
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // 7 - 0x70 -> 0x7F
// 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - A - B - C - D - E - F
};
// ############################ sendCMD deklarieren ##############################
void sendCMD(byte address, byte CMD, ... );
// ########################### Krams vorbereiten (fest) ##########################
unsigned char RainbowCMD[20];
unsigned char State = 0;
unsigned long timeout;
byte remoteAddr = 0x10;
// ########################## Krams vorbereiten (eigenes Zeug) ####################
int secondX[60] = {7,6,5,4,7,6,5,4,7,6,5,4,7,6,5,4,7,6,5,4,7,6,5,4,7,6,5,4,7,6,5,4,7,6,5,4,7,6,5,4,7,6,5,4,7,6,5,4,7,6,5,4,7,6,5,4,7,6,5,4};
int secondY[60] = {0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,0,0,0,0,1,1,1,1,2,2,2,2};
void setupRainbow() {
RainbowCMD[0] = 'r'; // Keine Ahnung
sendCMD(0x10, CMD_SET_PAPER, 0, 0, 0); // Inhalte löschen
sendCMD(0x10, CMD_CLEAR_PAPER);
sendCMD(0x10, CMD_SWAP_BUF);
Serial.println("rainbow init");
}
// ############################### Sekundentakt ##############################
void rainbowSecond(){
RainbowCMD[0] = 'r';
//sendCMD(0x10, CMD_CLEAR_PAPER);
//sendCMD(0x10, CMD_SET_INK, 0xF, 0x5, 0x5);
//sendCMD(0x10, CMD_DRAW_PIXEL,toByte(secondX[second()]),toByte(secondY[second()]));
//sendCMD(0x10, CMD_SWAP_BUF);
Serial.println("rainbow second");
}
// ##################################################################
/*
sendCMD(0x10, CMD_CLEAR_PAPER);
sendCMD(0x10, CMD_SET_INK, 0xD, 0xF, 0);
sendCMD(0x10, CMD_DRAW_SQUARE, toByte(6), toByte(1), toByte(5), toByte(2));
sendCMD(0x10, CMD_SWAP_BUF);
sendCMD(0x10, CMD_CLEAR_PAPER);
sendCMD(0x10, CMD_SWAP_BUF);
sendCMD(0x10, CMD_DRAW_SQUARE, toByte(7), toByte(0), toByte(4), toByte(3));
sendCMD(0x10, CMD_COPY_FRONT_BUF, toByte(0), toByte(-1));
sendCMD(0x10, CMD_SET_INK, 0x3, 0x10, 0xF);
sendCMD(0x10, CMD_DRAW_PIXEL,toByte(7),toByte(0));
sendCMD(0x10, CMD_SWAP_BUF);
int i=0;
byte x = 0;
byte y = 0;
int green=0;
int blue=0;
int red=0;
for (i= 0; i < 30; i++) {
x = random(4, 7);
y =random(0,4);
green= random(0,25);
red=random(0,255);
blue = random(0,255);
sendCMD(0x10, CMD_CLEAR_PAPER);
sendCMD(0x10, CMD_SET_INK, red, green, blue);
sendCMD(0x10, CMD_DRAW_PIXEL,toByte(x),toByte(y));
sendCMD(0x10, CMD_SWAP_BUF);
delay(100);
}
int i=0;
for (i= 0; i < 16; i++) {
sendCMD(0x10, CMD_CLEAR_PAPER);
sendCMD(0x10, CMD_SET_INK, 0xF, 0x5, 0x5);
sendCMD(0x10, CMD_DRAW_PIXEL,toByte(secondX[i]),toByte(secondY[i]));
sendCMD(0x10, CMD_SWAP_BUF);
Serial.print(i);
delay(900);
}
sendCMD(0x10, CMD_COPY_FRONT_BUF, toByte(0), toByte(-1));
sendCMD(0x10, CMD_CLEAR_PAPER);
sendCMD(0x10, CMD_SET_INK, 0xF, 0xF, 0xF);
sendCMD(0x10, CMD_DRAW_PIXEL,135,128);
sendCMD(0x10, CMD_SWAP_BUF);
Serial.println(toByte(secondX[0]),DEC);
Serial.println(toByte(secondY[0]),DEC);
delay(500);
// for (x= 0; x < 255; x++) {
// for (y=0; y<255;y++){
// }
// }
}
*/
unsigned char toByte(int i) {
return map(i, -128, 127, 0, 255);
}
void sendCMD(byte address, byte CMD, ... ) {
int i;
unsigned char v;
byte t;
va_list args; // Create a variable argument list
va_start(args, CMD); // Initialize the list using the pointer of the variable next to CMD;
RainbowCMD[1] = CMD; // Stores the command name
t = pgm_read_byte(&(CMD_totalArgs[CMD]))+2; // Retrieve the number of arguments for the command
for (i=2; i < t; i++) {
v = va_arg(args, int); // Retrieve the argument from the va_list
RainbowCMD[i] = v; // Store the argument
}
sendWireCommand(address, t); // Transmit the command via I2C
}
void sendWireCommand(int Add, byte len) {
unsigned char OK=0;
unsigned char i,temp;
while(!OK)
{
switch (State)
{
case 0:
Wire.beginTransmission(Add);
for (i=0; i<len ;i++) Wire.send(RainbowCMD[i]);
Wire.endTransmission();
delay(5);
State=1;
break;
case 1:
Wire.requestFrom(Add,1);
if (Wire.available()>0)
temp=Wire.receive();
else {
temp=0xFF;
timeout++;
}
if ((temp==1)||(temp==2)) State=2;
else if (temp==0) State=0;
if (timeout>5000) {
timeout=0;
State=0;
}
delay(5);
break;
case 2:
OK=1;
State=0;
break;
default:
State=0;
break;
}
}
}
Aber nicht meggern wenns unübersichtlich ist schönheit kommt zum schluss und es ist sicher nicht alles sauber gelößt.
Bin ja noch am Anfang
Edit:
Ich glaube der rest läuft auch nicht mehr richtig.
Die DCF-Zeit kommt falsch.
grrr ich muss los....