Coding for I/O Expansion Unit

Do you have a question on how to do something.
Ask in here.
Post Reply
rossbryant1956
Posts: 471
Joined: Sat Jan 14, 2012 2:08 pm
Location: Montgomery Village, MD

Coding for I/O Expansion Unit

Post by rossbryant1956 »

One of the things I like most to do is use the wizard to generate some code then compare it to what I doing, looking for improvements, ideas, etc.

Roberto and I wrote this code to monitor a float valve in my display tank, when tripped would sound the buzzer, turn off the pump, then send an alert to the portal which would alert me via text, email etc.

Code: Select all

//turn off port 8 - main pump when switch is tripped and sound buzzer 
     ReefAngel.Relay.Set(Port8,ReefAngel.IO.GetChannel(0));
     ReefAngel.PWM.SetDaylight(100-(ReefAngel.IO.GetChannel(0)*100)); 
          
     //tell the portal we have a overflow problem
     ReefAngel.CustomVar[0]=ReefAngel.IO.GetChannel(0);
     ReefAngel.CustomVar[7]=1;
I am now going to be adding more float valves to my new tanks and need to replicate this to monitor more floats, different relay ports and pumps, etc. I found this piece of code on the wizard

Code: Select all

// Initialize Buzzer variables
byte buzzer=0;
byte iochannel0flag=0;
byte iochannel1flag=0;
byte iochannel2flag=0;
byte iochannel3flag=0;
byte iochannel4flag=0;
byte iochannel5flag=0;

void loop()
{
    iochannel0flag = ReefAngel.IO.GetChannel( 0 );
    iochannel1flag = ReefAngel.IO.GetChannel( 1 );
    iochannel2flag = ReefAngel.IO.GetChannel( 2 );
    iochannel3flag = ReefAngel.IO.GetChannel( 3 );
    iochannel4flag = ReefAngel.IO.GetChannel( 4 );
    iochannel5flag = ReefAngel.IO.GetChannel( 5 );
    buzzer = iochannel0flag + iochannel1flag + iochannel2flag + iochannel3flag + iochannel4flag + iochannel5flag;
    if ( buzzer >= 1 ) buzzer = 100;
    ReefAngel.PWM.SetActinic( buzzer );

Can I use this to do what I want, monitor several floats, effect several ports based on individual valves and expand on the original code? Thanks in advance.
Roscoe's Reefs - Starting Over Again:

Building new 29g Nano after landlord went berserk over my 4 75 gallon tanks, Multiple RA's, Water mixing stations, etc. Your help welcomed in remembering all I've forgotten.
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Coding for I/O Expansion Unit

Post by rimai »

yes
Roberto.
rossbryant1956
Posts: 471
Joined: Sat Jan 14, 2012 2:08 pm
Location: Montgomery Village, MD

Re: Coding for I/O Expansion Unit

Post by rossbryant1956 »

So I am currently doing this:

Code: Select all

//turn off port 8 - DT pump when switch is tripped and sound buzzer 
     ReefAngel.Relay.Set(Port8,ReefAngel.IO.GetChannel(0));
     ReefAngel.PWM.SetDaylight(100-(ReefAngel.IO.GetChannel(0)*100)); 
    
//turn off port 7 - GT pump when switch is tripped and sound buzzer 
     ReefAngel.Relay.Set(Port7,ReefAngel.IO.GetChannel(1));
     ReefAngel.PWM.SetDaylight(100-(ReefAngel.IO.GetChannel(1)*100)); 
          
//tell the portal we have a overflow problem
     ReefAngel.CustomVar[0]=ReefAngel.IO.GetChannel(0);
     ReefAngel.CustomVar[1]=ReefAngel.IO.GetChannel(1);
     ReefAngel.CustomVar[7]=1;
And will be soon adding more float valves to do other things. I found this code using the wizard and wonder can I now do this:

Code: Select all

// Initialize Buzzer variables
byte buzzer=0;
byte iochannel0flag=0;
byte iochannel1flag=0;
byte iochannel2flag=0;
byte iochannel3flag=0;
byte iochannel4flag=0;
byte iochannel5flag=0;

void loop()
{
    iochannel0flag = ReefAngel.IO.GetChannel( 0 );
    iochannel1flag = ReefAngel.IO.GetChannel( 1 );
    iochannel2flag = ReefAngel.IO.GetChannel( 2 );
    iochannel3flag = ReefAngel.IO.GetChannel( 3 );
    iochannel4flag = ReefAngel.IO.GetChannel( 4 );
    iochannel5flag = ReefAngel.IO.GetChannel( 5 );
    buzzer = iochannel0flag + iochannel1flag + iochannel2flag + iochannel3flag + iochannel4flag + iochannel5flag;
    if ( buzzer >= 1 ) buzzer = 100;
    ReefAngel.PWM.SetDaylight( buzzer );

ReefAngel.Relay.Set(Port8,ReefAngel.IO.GetChannel(0));
ReefAngel.Relay.Set(Port7,ReefAngel.IO.GetChannel(1));

My questions are:

1. Will this work?
2. Should I do it, is it more efficient?
3. Realizing I use float valves differently, and alert on a "0" rather than a "1", should I change:

Code: Select all

byte iochannel0flag=0


to

Code: Select all

byte iochannel0flag=1
and finally if you want to review our discussion about the original design of this visit http://forum.reefangel.com/viewtopic.ph ... 7&start=60 but go all the way to page 7 to get to the point. Thx
Roscoe's Reefs - Starting Over Again:

Building new 29g Nano after landlord went berserk over my 4 75 gallon tanks, Multiple RA's, Water mixing stations, etc. Your help welcomed in remembering all I've forgotten.
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Coding for I/O Expansion Unit

Post by rimai »

Yes, you can use that.
But change it to like this if you want to check when the switch is floating.

Code: Select all

    iochannel0flag = !ReefAngel.IO.GetChannel( 0 );
The ! sign inverts the float check.
Roberto.
rossbryant1956
Posts: 471
Joined: Sat Jan 14, 2012 2:08 pm
Location: Montgomery Village, MD

Re: Coding for I/O Expansion Unit

Post by rossbryant1956 »

so zero and one are actually monitoring for a tank overflowing so they would need the ! because I need to know when they are floating...yes?

second, what about byte iochannel0flag=0

should it be a 1
Roscoe's Reefs - Starting Over Again:

Building new 29g Nano after landlord went berserk over my 4 75 gallon tanks, Multiple RA's, Water mixing stations, etc. Your help welcomed in remembering all I've forgotten.
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Coding for I/O Expansion Unit

Post by rimai »

The channel will be 0 when it is floating and 1 when it is not floating, assuming you mount them with the wires pointing up.
If you use the ! sign, it will change to the opposite, where 1 is floating and 0 it not floating.
Leave the variable declaration the way it is. There is no need to change that.
Roberto.
Post Reply