right place for M4 arduino ide compiler questions?

Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
drew1
 
Posts: 13
Joined: Fri Feb 12, 2021 6:43 am

right place for M4 arduino ide compiler questions?

Post by drew1 »

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?

User avatar
dastels
 
Posts: 15659
Joined: Tue Oct 20, 2015 3:22 pm

Re: right place for M4 arduino ide compiler questions?

Post by dastels »

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

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

Re: right place for M4 arduino ide compiler questions?

Post by drew1 »

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

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

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.

User avatar
dastels
 
Posts: 15659
Joined: Tue Oct 20, 2015 3:22 pm

Re: right place for M4 arduino ide compiler questions?

Post by dastels »

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

analogWrite(redPin, WaveLengthToRed(waveLength);
I see some capitalization and spelling inconsistencies as well. The compiler should be pointing those out as well.

Dave

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

Re: right place for M4 arduino ide compiler questions?

Post by drew1 »

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
*/

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

Re: right place for M4 arduino ide compiler questions?

Post by drew1 »

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.

User avatar
dastels
 
Posts: 15659
Joined: Tue Oct 20, 2015 3:22 pm

Re: right place for M4 arduino ide compiler questions?

Post by dastels »

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

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

Re: right place for M4 arduino ide compiler questions?

Post by drew1 »

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.

User avatar
dastels
 
Posts: 15659
Joined: Tue Oct 20, 2015 3:22 pm

Re: right place for M4 arduino ide compiler questions?

Post by dastels »

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

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

Re: right place for M4 arduino ide compiler questions?

Post by drew1 »

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.

Locked
Please be positive and constructive with your questions and comments.

Return to “Metro, Metro Express, and Grand Central Boards”