Hi all,
I'm trying to build a piece of test code that reads a digital pin state from my arduino (high or low). There are several of these, and then I'd like to pass the results to a CAN bus message function. The CAN bus code likes to see 8 bytes as it's input, so my code currently runs like this (I've removed the other inputs for clarity):
When I try to compile the code I get an error "warning: invalid conversion from 'const char*' to 'byte {aka unsigned char}' [-fpermissive]"
I don't understand the issue here? I tried changing the initiation of Horn from int Horn to byte Horn and that didn't seem to make any difference - do I need to change how I designate the input pin?
const int Horn_InputPin = 10;
int Horn = 0;
void setup() {
pinMode(Horn_InputPin, INPUT_PULLUP);
}
void loop() {
Horn_InputPin = !digitalRead(Horn_InputPin);
CAN_SEND("0x711", Horn, xxx, xxx, xxx, xxx, xxx, xxx, xxx); //FRAME 1
void CAN_SEND (byte ADDRESS, byte Slot1, byte Slot2, byte Slot3, byte Slot4, byte Slot5, byte Slot6, byte Slot7, byte Slot8) {
can_MsgTx.ext = 0;
can_MsgTx.id = ADDRESS; //xxxxx Soft Inputs 1-8 are in 0x710, 9-16 0x711 etc
can_MsgTx.len = 8;
can_MsgTx.buf[0] = Slot1; //Slot 1 (SideLights or Horn or LeftStalk poss)
can_MsgTx.buf[1] = Slot2; //Slot 2 (MainLights or WiperLow)
can_MsgTx.buf[2] = Slot3; //Slot 3 (HighLights or WiperHigh)
can_MsgTx.buf[3] = Slot4; //Slot 4 (HazLights or ScreenWash)
can_MsgTx.buf[4] = Slot5; //Slot 5 (IndL or AC Engage)
can_MsgTx.buf[5] = Slot6; //Slot 6 (IndR or Blower)
can_MsgTx.buf[6] = Slot7; //Slot 7 (FogR or Pop Boot)
can_MsgTx.buf[7] = Slot8; //Slot 8 (FogF or DoorsLocked)
can_MsgTx.flags.extended = 0;
can_MsgTx.flags.remote = 0;
// can_MsgTx.timeout = 500;
//Serial.print("CAN SENT: "); hexDump(8, can_MsgTx.buf); //Diagnostic - Dump message to Serial//@@@@@@@@@@@@@@@@@@@@@@@@@@@CAN DIAGNOSTICS@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Can0.write(can_MsgTx); //Send message
}
jimLee
February 1, 2021, 5:54am
2
You can't define a function inside of a function.
-jim lee
jimLee
February 1, 2021, 7:08am
4
By typing? You started loop() then started CAN_SEND()..
void loop() {
Horn_InputPin = !digitalRead(Horn_InputPin);
CAN_SEND("0x711", Horn, xxx, xxx, xxx, xxx, xxx, xxx, xxx); //FRAME 1
void CAN_SEND (byte ADDRESS, byte Slot1, byte Slot2, byte Slot3, byte Slot4, byte Slot5, byte Slot6, byte Slot7, byte Slot8) {
can_MsgTx.ext = 0;
can_MsgTx.id = ADDRESS; //xxxxx Soft Inputs 1-8 are in 0x710, 9-16 0x711 etc
can_MsgTx.len = 8;
can_MsgTx.buf[0] = Slot1; //Slot 1 (SideLights or Horn or LeftStalk poss)
can_MsgTx.buf[1] = Slot2; //Slot 2 (MainLights or WiperLow)
can_MsgTx.buf[2] = Slot3; //Slot 3 (HighLights or WiperHigh)
can_MsgTx.buf[3] = Slot4; //Slot 4 (HazLights or ScreenWash)
can_MsgTx.buf[4] = Slot5; //Slot 5 (IndL or AC Engage)
can_MsgTx.buf[5] = Slot6; //Slot 6 (IndR or Blower)
can_MsgTx.buf[6] = Slot7; //Slot 7 (FogR or Pop Boot)
can_MsgTx.buf[7] = Slot8; //Slot 8 (FogF or DoorsLocked)
can_MsgTx.flags.extended = 0;
can_MsgTx.flags.remote = 0;
// can_MsgTx.timeout = 500;
//Serial.print("CAN SENT: "); hexDump(8, can_MsgTx.buf); //Diagnostic - Dump message to Serial//@@@@@@@@@@@@@@@@@@@@@@@@@@@CAN DIAGNOSTICS@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Can0.write(can_MsgTx); //Send message
}
-jim lee
Ah yeah, I copied it out of the sketch wrong, my bad. My sketch does end the loop before the function is written; that's not the cause of the problem.
Horn_InputPin = !digitalRead(Horn_InputPin); that's not going to end well
jimLee
February 1, 2021, 8:24am
7
Niether will..
CAN_SEND("0x711",...
void CAN_SEND (byte ADDRESS,...
-jim lee
Thanks guys! Found and removed both errors and it compiles now, though I still get an advisory: "warning: large integer implicitly truncated to unsigned type"
I tried introducing the variables as unsigned integers and bytes and either way it doesn't change
450nick
February 1, 2021, 9:04am
10
Code attached
CAN_Translator_Rev_B.ino (10.1 KB)
After over three hundred posts, how about posting the exact error message you're getting?
(I'm on my phone, so I can't see your code, so maybe the error message will make things more obvious)
450nick
February 1, 2021, 9:10am
12
Here's the exact feedback:
CAN_Translator_Rev_B: In function 'void loop()':
CAN_Translator_Rev_B:254: warning: large integer implicitly truncated to unsigned type
CAN_SEND(FRAME1, SideLights, MainLights, HighLights, HazLights, IndLLights, IndRLights, RFogLights, FFogLights); //FRAME 1
^
CAN_Translator_Rev_B:255: warning: large integer implicitly truncated to unsigned type
CAN_SEND(FRAME2, Horn, WiperLow, WiperHigh, WiperWash, ACEngage, Blower, BootPop, DoorsLocked); //FRAME 2
^
CAN_Translator_Rev_B:256: warning: large integer implicitly truncated to unsigned type
CAN_SEND(FRAME3, LeftStalkButton, Spare1, Spare2, Spare3, Spare4, 0, 0, 0); //FRAME 3
CAN_SEND takes a bunch of byte parameters. You're passing a number of unsigned ints and worst of all - numbers like 0x710 which are probably important to get right but don't fit in a byte.