Newbie questionnaire

New members questions
Post Reply
User avatar
joshlawless
Posts: 138
Joined: Thu May 23, 2013 2:52 pm

Re: Newbie questionnaire

Post by joshlawless »

Before I unhook everything to upload the test code, can I double check that the custom function should be using 0x42 instead of 0x41 (based on 0x41 being the primary 16-channel PWM, that should be operable via the standard code)?

Also, forgive my asking again, but what is the syntax for the first 16-channel PWM, if this CustomExpansion() function is what I need for the second 16-channel PWM?
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Newbie questionnaire

Post by rimai »

You can copy the function and call it CustomExpansion1 and change the address to 0x42.
Roberto.
User avatar
joshlawless
Posts: 138
Joined: Thu May 23, 2013 2:52 pm

Re: Newbie questionnaire

Post by joshlawless »

So use the custom code for both, instead of custom code for one and the library support for the other?
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Newbie questionnaire

Post by rimai »

Yeah, you could do that.
The library already supports the 0x41.
Roberto.
User avatar
joshlawless
Posts: 138
Joined: Thu May 23, 2013 2:52 pm

Re: Newbie questionnaire

Post by joshlawless »

Should I want to use the library version, what would the function name and syntax be?

And do I need to change the name of the function if I only include one copy in my code?

Sorry for all the serial questions.
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Newbie questionnaire

Post by rimai »

You need to add this to setup to enable the feature:

Code: Select all

ReefAngel.Add16ChPWM();
Then you can use a function like:

Code: Select all

ReefAngel.PWM.Set16Channel(0,PWMSlope(9,0,20,0,15,100,60,15));
Roberto.
User avatar
joshlawless
Posts: 138
Joined: Thu May 23, 2013 2:52 pm

Re: Newbie questionnaire

Post by joshlawless »

Thanks much! This is enough to get me started, but I have a feeling I'll want to replicate the Set16ChannelRaw functionality from RA_PWM.h eventually. Hopefully by the time I'm ready to try that, I'll understand how to do it without so much hand-holding.
User avatar
joshlawless
Posts: 138
Joined: Thu May 23, 2013 2:52 pm

Re: Newbie questionnaire

Post by joshlawless »

On further consideration, is it necessary to have two copies of the named function? Since the CustomExpansion() function takes the address of the expansion board as its first variable (byte id), doesn't this mean I could simply pass 0x41 when I wanted to access the first expansion module, and 0x42 when I wanted to access the second?
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Newbie questionnaire

Post by rimai »

Yes, that is the best solution :)
I just didn't want to confuse too much, but it seems you are on top of things :)
Roberto.
User avatar
joshlawless
Posts: 138
Joined: Thu May 23, 2013 2:52 pm

Re: Newbie questionnaire

Post by joshlawless »

And if I wanted to rely on my custom function, I could change it up a bit:

Code: Select all

void CustomExpansion1(byte id, byte channel, int level)
{
  Wire.beginTransmission(id);
  Wire.write(0);
  Wire.write(0xa1);
  Wire.endTransmission();
  Wire.beginTransmission(id);
  Wire.write(0x8+(4*channel));
  Wire.write(level&0xff);
  Wire.write(level>>8);
  Wire.endTransmission();
}
To allow the function to accept a 12-bit integer, instead of a percentage. That way I could pass a high-definition value from one of the smooth slope functions, yes? (Assuming I haven't broken some variable naming rule with "level")
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Newbie questionnaire

Post by rimai »

Right on :)
Roberto.
User avatar
joshlawless
Posts: 138
Joined: Thu May 23, 2013 2:52 pm

Re: Newbie questionnaire

Post by joshlawless »

Since I've taken out the line that maps the percentage byte onto a 12-bit number, do I still need to have lines four and five in my CustomExpansion function:

Code: Select all

  Wire.endTransmission();
  Wire.beginTransmission(id);
It seems like there's no need to end then immediately start the transmission, but I don't know the Wire functions at all.
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Newbie questionnaire

Post by rimai »

Not sure. Try it :)
Roberto.
User avatar
joshlawless
Posts: 138
Joined: Thu May 23, 2013 2:52 pm

Re: Newbie questionnaire

Post by joshlawless »

Living dangerously! Will let you know what happens when I get it connected. :-)
Post Reply