jremington:
What part of "all of it" do you not understand?
The error message tells that you are defining a variable named DYNAMIC_CAN_MESSAGE_BYTES more than once. Don't do that.
I'm not defining that twice.
And sorry, it's quite a lot of code, didn't want to spam the whole topic.
I think this is all the code that matters, let me know if you're missing anything.
ibusGlobals.h - This is where the 'regular' ibus messages are stored
#ifndef IbusGlobals_h
#define IbusGlobals_h
#include <Arduino.h>
// Comment line to disable debug messages
#define IBUS_DEBUG
#define SEND_DEBUG
#define DISCARDED_DEBUG
// These tell the library which interface you're using. Only one can be selected.
#define MELEXIS
//#define MCP
extern const byte senSta; // sen/Sta output from Melexix TH3122.
extern const byte enable; // HIGH enables IBUS trasceiver chip.
extern volatile boolean clearToSend;
//extern const byte ledPin;
extern unsigned long ibusLoopTime;
extern unsigned long packetTimer;
//////////
//OUTPUT//
//////////
// LIGHTS //
const byte LIGHTS_OFF [20] = { //BASE
0x3F , 0x12 , 0xD0 , 0x0C , 0x00 , 0x00 , 0xFF , 0xFF , 0x00 , 0x00 , 0x00 , 0x80 , 0x00 , 0x80 , 0x80 , 0x00 , 0x00 , 0x00 , 0x00 , 0x71
};
const byte LIGHTS_STANDING [20] = {
0x3F , 0x12 , 0xD0 , 0x0C , 0x00 , 0x00 , 0xFF , 0xFF , 0x02 , 0x08 , 0x00 , 0x80 , 0x00 , 0x80 , 0x80 , 0x00 , 0x00 , 0x00 , 0x00 , 0x7B
};
const byte LIGHTS_FOG [20] = {
0x3F , 0x12 , 0xD0 , 0x0C , 0x00 , 0x00 , 0xFF , 0xFF , 0x00 , 0x00 , 0x01 , 0x80 , 0x00 , 0x80 , 0x80 , 0x00 , 0x00 , 0x00 , 0x00 , 0x70
};
//etc etc etc...
#endif
Then the Welcome Lights function is called:
void do_Welcome_Step_2() {
bool standing = true;
bool fog = true;
//Create new Canbus Message Array
byte DYNAMIC_CAN_MESSAGE_BYTES [20];
// Print LIGHTS_OFF to show default
curr_Time();
debugSerial.println(F("LIGHTS OFF (BASE):"));
curr_Time();
for (int i = 0; i < sizeof(LIGHTS_OFF); i++)
{
debugSerial.print(LIGHTS_OFF[i], HEX);
debugSerial.print(" ");
}
debugSerial.println();
// Overwrite old DYNAMIC_CAN_MESSAGE_BYTES values stored in memory
curr_Time();
debugSerial.println(F("Overwriting old DYNAMIC_CAN_MESSAGE_BYTES values stored in memory"));
for (byte i = 0; i < sizeof(DYNAMIC_CAN_MESSAGE_BYTES); i++) {
DYNAMIC_CAN_MESSAGE_BYTES[i] = 0;
}
// Print DYNAMIC_CAN_MESSAGE_BYTES after reset to 0000
curr_Time();
debugSerial.println(F("DYNAMIC_CAN_MESSAGE_BYTES (should be all 00):"));
curr_Time();
for (int i = 0; i < sizeof(DYNAMIC_CAN_MESSAGE_BYTES); i++)
{
debugSerial.print(DYNAMIC_CAN_MESSAGE_BYTES[i], HEX);
debugSerial.print(" ");
}
debugSerial.println();
// Print LIGHTS_OFF
curr_Time();
debugSerial.println(F("LIGHTS_OFF:"));
curr_Time();
for (int i = 0; i < sizeof(LIGHTS_OFF); i++)
{
debugSerial.print(LIGHTS_OFF[i], HEX);
debugSerial.print(" ");
}
debugSerial.println();
// Print LIGHTS_STANDING
curr_Time();
debugSerial.println(F("LIGHTS_STANDING:"));
curr_Time();
for (int i = 0; i < sizeof(LIGHTS_STANDING); i++)
{
debugSerial.print(LIGHTS_STANDING[i], HEX);
debugSerial.print(" ");
}
debugSerial.println();
// Print LIGHTS_FOG
curr_Time();
debugSerial.println(F("LIGHTS_FOG:"));
curr_Time();
for (int i = 0; i < sizeof(LIGHTS_FOG); i++)
{
debugSerial.print(LIGHTS_FOG[i], HEX);
debugSerial.print(" ");
}
debugSerial.println();
// Calculate DYNAMIC_CAN_MESSAGE_BYTES
curr_Time();
debugSerial.println(F("For loop setting DYNAMIC_CAN_MESSAGE_BYTES:"));
for (int i = 0; i < sizeof(DYNAMIC_CAN_MESSAGE_BYTES); i++) {
curr_Time();
debugSerial.print(i);
debugSerial.print(": ");
// First 4 bytes are always the same. Just copy from LIGHTS_OFF
if (i < 4) {
DYNAMIC_CAN_MESSAGE_BYTES[i] = LIGHTS_OFF[i];
debugSerial.print("Copy Base: ");
debugSerial.println(DYNAMIC_CAN_MESSAGE_BYTES[i], HEX);
}
// Byte 4 and 5 have to be added
if (i == 4 || i == 5) {
if (standing) {
DYNAMIC_CAN_MESSAGE_BYTES[i] += LIGHTS_STANDING[i];
}
if (fog) {
DYNAMIC_CAN_MESSAGE_BYTES[i] += LIGHTS_FOG[i];
}
debugSerial.print(LIGHTS_OFF[i], HEX);
debugSerial.print("+");
debugSerial.print(LIGHTS_STANDING[i], HEX);
debugSerial.print("=");
debugSerial.println(LIGHTS_OFF[i] + LIGHTS_STANDING[i], HEX);
}
// Bytes 6 is always the same. Just copy from LIGHTS_OFF
if (i == 6) {
DYNAMIC_CAN_MESSAGE_BYTES[i] = LIGHTS_OFF[i];
debugSerial.print("Copy Base: ");
debugSerial.println(DYNAMIC_CAN_MESSAGE_BYTES[i], HEX);
}
if (i == 7) {
DYNAMIC_CAN_MESSAGE_BYTES[i] = LIGHTS_OFF[i]; // This one has to be changed. It should also calculate, but these default values are FF... instead of 00
debugSerial.print("Copy Base: ");
debugSerial.print(DYNAMIC_CAN_MESSAGE_BYTES[i], HEX);
debugSerial.println(" (FOR NOW...)");
}
// Byte 8 - 10 have to be added
if (i >= 8 && i <= 10) {
if (standing) {
DYNAMIC_CAN_MESSAGE_BYTES[i] += LIGHTS_STANDING[i];
}
if (fog) {
DYNAMIC_CAN_MESSAGE_BYTES[i] += LIGHTS_FOG[i];
}
debugSerial.print(LIGHTS_OFF[i], HEX);
debugSerial.print("+");
debugSerial.print(LIGHTS_STANDING[i], HEX);
debugSerial.print("=");
debugSerial.println(LIGHTS_OFF[i] + LIGHTS_STANDING[i], HEX);
}
// Last 8 bytes are always the same. Just copy from LIGHTS_OFF
if (i >= 11 && i <= 18) {
DYNAMIC_CAN_MESSAGE_BYTES[i] = LIGHTS_OFF[i];
debugSerial.print("Copy Base: ");
debugSerial.println(DYNAMIC_CAN_MESSAGE_BYTES[i], HEX);
}
// Calculate and Add Checksum to DYNAMIC_CAN_MESSAGE_BYTES
if (i == 19) {
debugSerial.print("Checksum: ");
for (byte i = 0; i < 19; i++) {
DYNAMIC_CAN_MESSAGE_BYTES[19] ^= DYNAMIC_CAN_MESSAGE_BYTES[i];
}
debugSerial.println(DYNAMIC_CAN_MESSAGE_BYTES[19], HEX);
}
}
// Print LIGHTS_OFF
curr_Time();
debugSerial.println(F("LIGHTS_OFF:"));
curr_Time();
for (int i = 0; i < sizeof(LIGHTS_OFF); i++)
{
debugSerial.print(LIGHTS_OFF[i], HEX);
debugSerial.print(" ");
}
debugSerial.println();
// Print LIGHTS_STANDING
curr_Time();
debugSerial.println(F("LIGHTS_STANDING:"));
curr_Time();
for (int i = 0; i < sizeof(LIGHTS_STANDING); i++)
{
debugSerial.print(LIGHTS_STANDING[i], HEX);
debugSerial.print(" ");
}
debugSerial.println();
// Print LIGHTS_FOG
curr_Time();
debugSerial.println(F("LIGHTS_FOG:"));
curr_Time();
for (int i = 0; i < sizeof(LIGHTS_FOG); i++)
{
debugSerial.print(LIGHTS_FOG[i], HEX);
debugSerial.print(" ");
}
debugSerial.println();
// Print DYNAMIC_CAN_MESSAGE_BYTES
curr_Time();
debugSerial.println("DYNAMIC_CAN_MESSAGE_BYTES:");
curr_Time();
for (int i = 0; i < sizeof(DYNAMIC_CAN_MESSAGE_BYTES); i++)
{
debugSerial.print(DYNAMIC_CAN_MESSAGE_BYTES[i], HEX);
debugSerial.print(" ");
}
debugSerial.println();
// SEND DYNAMIC_CAN_MESSAGE_BYTES over BUS
curr_Time();
debugSerial.println(F("SENDING: DYNAMIC_CAN_MESSAGE_BYTES"));
ibus.write(DYNAMIC_CAN_MESSAGE_BYTES, sizeof(DYNAMIC_CAN_MESSAGE_BYTES));
}
The screenshot I provided earlier shows the difference between the print of DYNAMIC_CAN_MESSAGE_BYTES and the actual message being sent with ibus.write(DYNAMIC_CAN_MESSAGE_BYTES, sizeof(DYNAMIC_CAN_MESSAGE_BYTES));
ibus.write is a function in a library I use.
will post remaining code in 5min (time restriction)