0

right place for M4 arduino ide compiler questions?
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

right place for M4 arduino ide compiler questions?

by drew1 on Fri Sep 17, 2021 11:52 am

Before I take up everybody's time and Adafruit server space, is this the right place to ask a question about an arduino ide compiler error for a sketch to run on M4bMetro Express?

drew1
 
Posts: 13
Joined: Fri Feb 12, 2021 6:43 am

Re: right place for M4 arduino ide compiler questions?

by dastels on Fri Sep 17, 2021 11:53 am

Here is probably fine, it could be directly related to the board. Another place is the help-with-arduino room on the Adafruit discord server.

I'd probably try here first.

Dave

dastels
 
Posts: 7510
Joined: Tue Oct 20, 2015 3:22 pm

Re: right place for M4 arduino ide compiler questions?

by drew1 on Fri Sep 17, 2021 1:38 pm

Thanks Dave. I remember the big help from you and others here getting up and going.

M4 Metro Express
Arduino IDE
Project going through wavelengths of visible light on Newtons Color Scale using RGB LED
Compiler error: invalid conversion from 'int (*)(int)' to 'uint32_t' {aka 'long unsigned int'} [-fpermissive]

This is one of many, but it is the one I am having trouble understanding. I have internet searched type cast.

Here is loop function where the line: analogWrite(greenPin, WaveLengthToGreen); is highlighted.

Code: Select all | TOGGLE FULL SIZE
void loop()
{
  for(int waveLength = 380; waveLength <= 700; waveLength ++)
  {
    Serial.println(waveLength);
    analogWrite(redPin, WaveLengthToRed);
    analogWrite(greenPin, WaveLengthToGreen);
    analogWrite(bluePin, WaveLengthToBlue);
    delay(timePeriod);
  }
}


called function:
Code: Select all | TOGGLE FULL SIZE
int waveLengthToGreen (int WaveLenght)
{
  float factor = 0;
  if ((waveLength >= 440) && (waveLength < 490))
  {
    factor = ((waveLenght - 440) / (490 - 440));
  }
  else if ((waveLength >= 490) && (waveLength < 580))
  {
    factor = 1.0;
  }
  else if ((waveLength >= 580) && (waveLength < 645))
  {
    factor = ((waveLength - 580) / 645 - 580));
  }
  else
  {
    factor = 0;
  }
  int greenPwm = factor * 255;
  return greenPwm;
}


I think my problem is multiplying the float factor * 255
This is to be returned to the loop function to analogWrite the result to the green pin.
I did not make int greenPwm a global variable.

drew1
 
Posts: 13
Joined: Fri Feb 12, 2021 6:43 am

Re: right place for M4 arduino ide compiler questions?

by dastels on Fri Sep 17, 2021 2:24 pm

The immediate problem I see is that you are using the functions (WaveLengthTo...) as the values to write; not calling them and using the resulting value.
You, insteadm, need to E.g.:
Code: Select all | TOGGLE FULL SIZE
analogWrite(redPin, WaveLengthToRed(waveLength);


I see some capitalization and spelling inconsistencies as well. The compiler should be pointing those out as well.

Dave

dastels
 
Posts: 7510
Joined: Tue Oct 20, 2015 3:22 pm

Re: right place for M4 arduino ide compiler questions?

by drew1 on Fri Sep 17, 2021 4:36 pm

Thanks

Yep, the compiler is worse than my old English teacher and is catching all of the capitalization, spelling, etc

I hope to try by tomorrow.

I'm just now getting some understanding about passing a parameter to a function and getting the result returned. Appreciate you helping me understand.

One think I forgot to do in my post was give credit to the guy that came up with the alogoritms that I used.
From comments:
wavelength to RGB calculations converted from JAVA SCRIPT
written by Captain Anonymous
on https://codepen.io/pen/?&editors=011
*/

drew1
 
Posts: 13
Joined: Fri Feb 12, 2021 6:43 am

Re: right place for M4 arduino ide compiler questions?

by drew1 on Mon Sep 20, 2021 2:57 pm

Have gone back though at various intervals though the weekend correcting spelling the variables the same in different places, punctuation, etc.

To call the function and then use the value it returns is this what I do?

analogWrite(redPin, WaveLengthToRed(waveLength));

I am now doing this in loop() function.
I did initialize functions above the serial() and the defined them below loop()

Going to have to put this down for a day or two, but will get back in a couple of days.

drew1
 
Posts: 13
Joined: Fri Feb 12, 2021 6:43 am

Re: right place for M4 arduino ide compiler questions?

by dastels on Mon Sep 20, 2021 5:12 pm

drew1 wrote:Have gone back though at various intervals though the weekend correcting spelling the variables the same in different places, punctuation, etc.

To call the function and then use the value it returns is this what I do?

analogWrite(redPin, WaveLengthToRed(waveLength));


Yes. you call WaveLengthToRed, passing it waveLength and use the returned value as value to analogWrite to pin redPin.

drew1 wrote:I am now doing this in loop() function.
I did initialize functions above the serial() and the defined them below loop.


I'm not sure what you mean by initialize functions.

Dave

dastels
 
Posts: 7510
Joined: Tue Oct 20, 2015 3:22 pm

Re: right place for M4 arduino ide compiler questions?

by drew1 on Tue Sep 21, 2021 11:05 am

I probably have not used the right term. This is what I mean by initialize:

//funtion prototypes
int WaveLengthToRed (int waveLenght);
int waveLengthToGreen (int wavelength);
int waveLengthToBlue (int waveLength);

I just plugged in to the board, so we will see how it works.

I appreciate your help.

drew1
 
Posts: 13
Joined: Fri Feb 12, 2021 6:43 am

Re: right place for M4 arduino ide compiler questions?

by dastels on Tue Sep 21, 2021 11:09 am

Ah. That's called declaring the functions. Later in the code you define them. The former makes the name known for use, while the latter provides the implementation.

Dave

dastels
 
Posts: 7510
Joined: Tue Oct 20, 2015 3:22 pm

Re: right place for M4 arduino ide compiler questions?

by drew1 on Tue Sep 21, 2021 12:26 pm

Looks like this old man doesn't know what he is talking about (inialize, declare, etc).

Now with two tabs open on the compiler, I have a mess. I will try to do some more tomorrow evening.

drew1
 
Posts: 13
Joined: Fri Feb 12, 2021 6:43 am

Please be positive and constructive with your questions and comments.