view release on metacpan or search on metacpan
docs/Acme-FishFarm-1.01.html view on Meta::CPAN
<pre><code> use 5.010;
use Acme::FishFarm ":all";
my $water_monitor = Acme::FishFarm::WaterConditionMonitor->install;
my $oxygen = Acme::FishFarm::OxygenMaintainer->install( DO_generation_volume => 1.92 );
$water_monitor->add_oxygen_maintainer( $oxygen );
say "Water condition monitor installed...";
say "Oxygen maintainer installed and connected to water condition monitor...";
say "Water condition monitor switched on!";
say "";
while ( "fish are swimming happily" ) {
### DO
check_DO( $oxygen, reduce_precision( rand(8) ) );
say "";
### pH
check_pH( $water_monitor, 6.912 );
#check_pH( $water_monitor, 5.9 );
say "" ;
## temperature
#check_temperature( $water_monitor, 23 );
check_temperature( $water_monitor, 26 );
say "";
## turbidity
check_turbidity( $water_monitor, 120 );
#check_turbidity( $water_monitor, 190 );
say "";
# all LEDs
render_leds( $water_monitor );
say "";
# buzzers
render_buzzer( $water_monitor );
sleep(3);
say "-----------------------------";
}
</code></pre>
<h1 id="EXPORT">EXPORT</h1>
<p>The <code>:all</code> tag can be used to import all the subroutines available in this module.</p>
<h1 id="NOTES">NOTES</h1>
<p>Almost all the subroutines in this module will give output. The unit measurements used will be according to the ones mentioned in <code>Acme::FishFarm::WaterConditionMonitor</code>.</p>
docs/Acme-FishFarm-Feeder-1.01.html view on Meta::CPAN
<p>Version 1.01</p>
<h1 id="SYNOPSIS">SYNOPSIS</h1>
<pre><code> use 5.010;
use Acme::FishFarm::Feeder;
my $feeder = Acme::FishFarm::Feeder->install( timer => 3, feeding_volume => 150 );
say "Feeder installed and switched on!";
say "";
while ( "fish are living happilly" ) {
if ( $feeder->timer_is_up ) {
say "\nTimer is up, time to feed the fish!";
say "Feeding ", $feeder->feeding_volume, " cm^3 of fish food to the fish...";
$feeder->feed_fish;
say $feeder->food_remaining, " cm^3 of fish food remaining in the tank.\n";
}
if ( $feeder->food_remaining <= 0 ) {
$feeder->refill; # default back to 500 cm^3
say "Refilled food tank back to ", $feeder->food_tank_capacity, " cm^3.\n";
}
say $feeder->time_remaining, " hours left until it's time to feed the fish.";
sleep(1);
$feeder->tick_clock;
}
say "";
say "Feeder was switched off, please remeber to feed your fish on time :)";</code></pre>
<h1 id="EXPORT">EXPORT</h1>
<p>None</p>
<h1 id="CREATION-RELATED-METHODS">CREATION RELATED METHODS</h1>
<h2 id="install-options">install ( %options )</h2>
<p>Installs an automated fish feeder.</p>
docs/Acme-FishFarm-OxygenMaintainer-1.01.html view on Meta::CPAN
<p>Version 1.01</p>
<h1 id="SYNOPSIS">SYNOPSIS</h1>
<pre><code> use 5.010;
use Acme::FishFarm qw(consume_oxygen reduce_precision);
use Acme::FishFarm::OxygenMaintainer;
my $oxygen = Acme::FishFarm::OxygenMaintainer->install( DO_generation_volume => 3 );
say "Oxygen maintainer installed!\n";
while ( "fish are using up oxygen" ) {
say "Current Oxygen Level: ", $oxygen->current_DO, " mg/L",
" (low: < ", $oxygen->DO_threshold, ")";
#say "Low Oxygen Level: ", $oxygen->DO_threshold, " mg/L";
if ( $oxygen->is_low_DO ) {
say "Fish status: Suffocating";
say " !! Low oxygen level!";
say "Pumping ", $oxygen->oxygen_generation_volume, " mg/L of oxygen into the water..." ;
$oxygen->generate_oxygen;
} else {
say "Fish status: Happy";
}
consume_oxygen( $oxygen, rand(2.5) );
sleep(3);
say "";
}</code></pre>
<h1 id="EXPORT">EXPORT</h1>
<p>None</p>
<h1 id="CREATION-RELATED-SUBROUTINES-METHODS">CREATION RELATED SUBROUTINES/METHODS</h1>
<h2 id="install-options">install ( %options )</h2>
docs/Acme-FishFarm-WaterFiltration-1.01.html view on Meta::CPAN
<h1 id="SYNOPSIS">SYNOPSIS</h1>
<pre><code> use 5.010;
use Acme::FishFarm qw( reduce_precision );
use Acme::FishFarm::WaterFiltration;
my $water_filter = Acme::FishFarm::WaterFiltration->install;
say "Water filter installed and switched on!\n";
my $current_reading;
my $waste_count_threshold;
while ( "Fish are living under the water..." ) {
$water_filter->current_waste_count( reduce_precision ( rand(100) ) );
$current_reading = $water_filter->current_waste_count;
$waste_threshold = $water_filter->waste_count_threshold;
docs/Acme-FishFarm-WaterFiltration-1.01.html view on Meta::CPAN
print "Current Waste Count: ", $current_reading, " (high: >= ", $waste_threshold, ")\n";
if ( $water_filter->is_cylinder_dirty ) {
print " !! Filtering cylinder is dirty!\n";
print " Cleaned the filter!\n";
$water_filter->clean_cylinder;
} else {
print " Filtering cylinder is still clean.\n";
}
sleep(1);
say "";
}</code></pre>
<h1 id="EXPORT">EXPORT</h1>
<p>None</p>
<h1 id="DESCRIPTION">DESCRIPTION</h1>
<p>This module assumes a cool water filter with a filtering cylinder constantly filtering water in the tank. It has inlet, outlet and a drainage valves. The drainage valve is only opened when the cleaners are switched on automatically to remove waste...
docs/Acme-FishFarm-WaterLevelMaintainer-1.01.html view on Meta::CPAN
<h1 id="SYNOPSIS">SYNOPSIS</h1>
<pre><code> use 5.010;
use Acme::FishFarm qw( reduce_precision );
use Acme::FishFarm::WaterFiltration;
my $water_level = Acme::FishFarm::WaterLevelMaintainer->install;
say "Water level maintainer installed and switched on!\n";
my $height_increase;
my $water_level_threshold;
my $current_reading;
while ( "Fish are living under the water..." ) {
$current_reading = reduce_precision( rand(10) );
$height_increase = $water_level->water_level_increase_height;
$water_level_threshold = $water_level->low_water_level_threshold;
docs/Acme-FishFarm-WaterLevelMaintainer-1.01.html view on Meta::CPAN
if ( $water_level->is_low_water_level ) {
print " !! Water level is low!\n";
$water_level->pump_water_in;
print " Pumping in ", $height_increase, " m of water...\n";
print "Current Water Level: ", $water_level->current_water_level, "\n";
} else {
print " Water level is still normal.\n";
}
sleep(1);
say "";
}</code></pre>
<h1 id="EXPORT">EXPORT</h1>
<p>None</p>
<h1 id="CREATION-RELATED-MEHODS">CREATION RELATED MEHODS</h1>
<h2 id="install-options">install ( %options )</h2>
lib/Acme/FishFarm.pm view on Meta::CPAN
use 5.010;
use Acme::FishFarm ":all";
my $water_monitor = Acme::FishFarm::WaterConditionMonitor->install;
my $oxygen = Acme::FishFarm::OxygenMaintainer->install( DO_generation_volume => 1.92 );
$water_monitor->add_oxygen_maintainer( $oxygen );
say "Water condition monitor installed...";
say "Oxygen maintainer installed and connected to water condition monitor...";
say "Water condition monitor switched on!";
say "";
while ( "fish are swimming happily" ) {
### DO
check_DO( $oxygen, reduce_precision( rand(8) ) );
say "";
### pH
check_pH( $water_monitor, 6.912 );
#check_pH( $water_monitor, 5.9 );
say "" ;
## temperature
#check_temperature( $water_monitor, 23 );
check_temperature( $water_monitor, 26 );
say "";
## turbidity
check_turbidity( $water_monitor, 120 );
#check_turbidity( $water_monitor, 190 );
say "";
# all LEDs
render_leds( $water_monitor );
say "";
# buzzers
render_buzzer( $water_monitor );
sleep(3);
say "-----------------------------";
}
=head1 EXPORT
The C<:all> tag can be used to import all the subroutines available in this module.
=cut
use Exporter qw( import );
our @EXPORT_OK = qw(
lib/Acme/FishFarm/Feeder.pm view on Meta::CPAN
our $VERSION = '1.01';
=head1 SYNOPSIS
use 5.010;
use Acme::FishFarm::Feeder;
my $feeder = Acme::FishFarm::Feeder->install( timer => 3, feeding_volume => 150 );
say "Feeder installed and switched on!";
say "";
while ( "fish are living happilly" ) {
if ( $feeder->timer_is_up ) {
say "\nTimer is up, time to feed the fish!";
say "Feeding ", $feeder->feeding_volume, " cm^3 of fish food to the fish...";
$feeder->feed_fish;
say $feeder->food_remaining, " cm^3 of fish food remaining in the tank.\n";
}
if ( $feeder->food_remaining <= 0 ) {
$feeder->refill; # default back to 500 cm^3
say "Refilled food tank back to ", $feeder->food_tank_capacity, " cm^3.\n";
}
say $feeder->time_remaining, " hours left until it's time to feed the fish.";
sleep(1);
$feeder->tick_clock;
}
say "";
say "Feeder was switched off, please remeber to feed your fish on time :)";
=head1 EXPORT
None
=head1 CREATION RELATED METHODS
=head2 install ( %options )
Installs an automated fish feeder.
lib/Acme/FishFarm/Feeder.pm view on Meta::CPAN
}
if ( not $options{food_tank_capacity} ) {
$options{food_tank_capacity} = 500;
}
if ( not $options{current_food_amount} ) {
$options{current_food_amount} = $options{food_tank_capacity};
}
$options{first_usage} = 1; # make sure the feeder doesn't say timer is up as soon as it is switched on
bless \%options, $class;
}
=head1 TIMER RELATED SUBROUTINES/METHODS
=head2 get_timer
lib/Acme/FishFarm/OxygenMaintainer.pm view on Meta::CPAN
=head1 SYNOPSIS
use 5.010;
use Acme::FishFarm qw(consume_oxygen reduce_precision);
use Acme::FishFarm::OxygenMaintainer;
my $oxygen = Acme::FishFarm::OxygenMaintainer->install( DO_generation_volume => 3 );
say "Oxygen maintainer installed!\n";
while ( "fish are using up oxygen" ) {
say "Current Oxygen Level: ", $oxygen->current_DO, " mg/L",
" (low: < ", $oxygen->DO_threshold, ")";
#say "Low Oxygen Level: ", $oxygen->DO_threshold, " mg/L";
if ( $oxygen->is_low_DO ) {
say "Fish status: Suffocating";
say " !! Low oxygen level!";
say "Pumping ", $oxygen->oxygen_generation_volume, " mg/L of oxygen into the water..." ;
$oxygen->generate_oxygen;
} else {
say "Fish status: Happy";
}
consume_oxygen( $oxygen, rand(2.5) );
sleep(3);
say "";
}
=head1 EXPORT
None
=head1 CREATION RELATED SUBROUTINES/METHODS
=head2 install ( %options )
lib/Acme/FishFarm/WaterFiltration.pm view on Meta::CPAN
=head1 SYNOPSIS
use 5.010;
use Acme::FishFarm qw( reduce_precision );
use Acme::FishFarm::WaterFiltration;
my $water_filter = Acme::FishFarm::WaterFiltration->install;
say "Water filter installed and switched on!\n";
my $current_reading;
my $waste_count_threshold;
while ( "Fish are living under the water..." ) {
$water_filter->current_waste_count( reduce_precision ( rand(100) ) );
$current_reading = $water_filter->current_waste_count;
$waste_threshold = $water_filter->waste_count_threshold;
lib/Acme/FishFarm/WaterFiltration.pm view on Meta::CPAN
print "Current Waste Count: ", $current_reading, " (high: >= ", $waste_threshold, ")\n";
if ( $water_filter->is_cylinder_dirty ) {
print " !! Filtering cylinder is dirty!\n";
print " Cleaned the filter!\n";
$water_filter->clean_cylinder;
} else {
print " Filtering cylinder is still clean.\n";
}
sleep(1);
say "";
}
=head1 EXPORT
None
=head1 DESCRIPTION
This module assumes a cool water filter with a filtering cylinder constantly filtering water in
the tank. It has inlet, outlet and a drainage valves. The drainage valve is only opened when the
lib/Acme/FishFarm/WaterLevelMaintainer.pm view on Meta::CPAN
=head1 SYNOPSIS
use 5.010;
use Acme::FishFarm qw( reduce_precision );
use Acme::FishFarm::WaterFiltration;
my $water_level = Acme::FishFarm::WaterLevelMaintainer->install;
say "Water level maintainer installed and switched on!\n";
my $height_increase;
my $water_level_threshold;
my $current_reading;
while ( "Fish are living under the water..." ) {
$current_reading = reduce_precision( rand(10) );
$height_increase = $water_level->water_level_increase_height;
$water_level_threshold = $water_level->low_water_level_threshold;
lib/Acme/FishFarm/WaterLevelMaintainer.pm view on Meta::CPAN
if ( $water_level->is_low_water_level ) {
print " !! Water level is low!\n";
$water_level->pump_water_in;
print " Pumping in ", $height_increase, " m of water...\n";
print "Current Water Level: ", $water_level->current_water_level, "\n";
} else {
print " Water level is still normal.\n";
}
sleep(1);
say "";
}
=head1 EXPORT
None
=head1 CREATION RELATED MEHODS
=head2 install ( %options )
scripts/feeder.pl view on Meta::CPAN
#!/usr/bin/perl
use strict;
use warnings;
use 5.010;
use Acme::FishFarm::Feeder;
my $feeder = Acme::FishFarm::Feeder->install( timer => 3, feeding_volume => 150 );
say "Feeder installed and switched on!";
say "";
#while (1) {
for (0..20){
if ( $feeder->timer_is_up ) {
say "\nTimer is up, time to feed the fish!";
say "Feeding ", $feeder->feeding_volume, " cm^3 of fish food to the fish...";
$feeder->feed_fish ( verbose => 1 );
say $feeder->food_remaining, " cm^3 of fish food remaining in the tank.\n";
}
if ( $feeder->food_remaining <=0 ) {
$feeder->refill; # default back to 500 cm^3
say "Refilled food tank back to ", $feeder->food_tank_capacity, " cm^3.\n";
}
say $feeder->time_remaining, " hours left until it's time to feed the fish.";
sleep(1);
$feeder->tick_clock;
}
say "";
say "Feeder was switched off, please remeber to feed your fish on time :)";
# besiyata d'shmaya
scripts/feeder_2.pl view on Meta::CPAN
use 5.010;
use Acme::FishFarm ":all";
use Acme::FishFarm::Feeder;
my $feeder = Acme::FishFarm::Feeder->install( timer => 3, feeding_volume => 150 );
while ( "fish are living in the water..." ) {
check_feeder( $feeder, verbose => 1 );
sleep 2;
say "";
}
# besiyata d'shmaya
scripts/fish_farm.pl view on Meta::CPAN
use warnings;
use 5.010;
use Acme::FishFarm ":all";
my $water_monitor = Acme::FishFarm::WaterConditionMonitor->install;
my $oxygen = Acme::FishFarm::OxygenMaintainer->install( DO_generation_volume => 1.92 );
$water_monitor->add_oxygen_maintainer( $oxygen );
say "Water condition monitor installed...";
say "Oxygen maintainer installed and connected to water condition monitor...";
say "Water condition monitor switched on!";
say "";
# my $first_round = 1; # not applicable for manual input
while ( "fish are swimming happily" ) {
### DO
check_DO( $oxygen, reduce_precision( rand(8) ) );
say "";
### pH
check_pH( $water_monitor, 6.912 );
#check_pH( $water_monitor, 5.9 );
say "" ;
## temperature
#check_temperature( $water_monitor, 23 );
check_temperature( $water_monitor, 26 );
say "";
## turbidity
check_turbidity( $water_monitor, 120 );
#check_turbidity( $water_monitor, 190 );
say "";
# all LEDs
render_leds( $water_monitor );
#if ( $water_monitor->is_on_LED_DO ) {
# say " Low oxygen LED: up";
#}
say "";
# buzzers
render_buzzer( $water_monitor );
sleep(3);
say "-----------------------------";
}
# besiyata d'shmaya
scripts/fish_farm_2.pl view on Meta::CPAN
my ( $feeder, $oxygen, $water_monitor, $water_level, $water_filter ) = install_all_systems;
show_installation_status();
sleep 1;
show_all_threshold();
$water_level->set_water_level_increase_height(5);
my $feeder_verbose = 1;
print colored(['bold bright_blue'], "Prese <ENTER> to start monitoring your fish farm"); <>;
say "";
while ( "fish are swimming happily" ) {
# get input for DO, pH, temperature, turbidity, in one go
print colored(['bold bright_blue'], "Enter current DO level (mg/L): ");
chomp ( my $current_DO = <>);
print colored(['bold bright_blue'], "Enter current pH value: ");
chomp ( my $current_pH = <>);
print colored(['bold bright_blue'], "Enter current temperature (C): ");
chomp ( my $current_temperature = <>);
print colored(['bold bright_blue'], "Enter current turbidity (ntu): ");
chomp ( my $current_turbidity = <>);
say colored(['bright_yellow'], "--------------------------------");
say colored(['bold bright_yellow'], "Water Condition Monitor Report");
say colored(['bright_yellow'], "--------------------------------");
check_DO( $oxygen, $current_DO ); say "";
check_pH( $water_monitor, $current_pH ); say "" ;
check_temperature( $water_monitor, $current_temperature ); say "";
check_turbidity( $water_monitor, $current_turbidity );
say colored(['bright_yellow'], "--------------------------------"); say "";
print colored(['bold bright_blue'], "Press <ENTER> to check the LED status"); <>; say "";
say colored(['bright_yellow'], "------------------------------------");
say colored(['bold bright_yellow'], "Water Condition Monitor LEDs Status");
say colored(['bright_yellow'], "------------------------------------");
render_leds( $water_monitor );
say colored(['bright_yellow'], "--------------------------------"); say "";
print colored(['bold bright_blue'], "Press <ENTER> to check the buzzer status"); <>; say "";
say colored(['bright_yellow'], "--------------------------------------");
say colored(['bold bright_yellow'], "Water Condition Monitor Buzzer Status");
say colored(['bright_yellow'], "--------------------------------------");
render_buzzer( $water_monitor );
say colored(['bright_yellow'], "--------------------------------------"); say "";
print colored(['bold bright_blue'], "Press <ENTER> to check the feeder"); <>; say "";
say colored(['bright_yellow'], "--------------------------------");
say colored(['bold bright_yellow'], "Automated Feeder Report");
say colored(['bright_yellow'], "--------------------------------");
check_feeder( $feeder, $feeder_verbose );
say colored(['bright_yellow'], "--------------------------------"); say "";
print colored(['bold bright_blue'], "Enter current waste count (integer): ");
chomp ( my $current_waste_count = <>);
say colored(['bright_yellow'], "--------------------------------");
say colored(['bold bright_yellow'], "Water Filtration Report");
say colored(['bright_yellow'], "--------------------------------");
check_water_filter( $water_filter, $current_waste_count );
say colored(['bright_yellow'], "--------------------------------"); say "";
print colored(['bold bright_blue'], "Enter current water level (m): ");
chomp ( my $current_water_level = <>);
say colored(['bright_yellow'], "----------------------------------");
say colored(['bold bright_yellow'], "Water Level Maintainer Report");
say colored(['bright_yellow'], "-----------------------------------");
check_water_level( $water_level, $current_water_level );
say colored(['bright_yellow'], "-----------------------------------"); say "";
say colored(['bold bright_yellow'], "-------------END OF REPORT-----------\n");
print colored(['bold bright_blue'], "Press <ENTER> to monitor your fish farm again"); <>;
say "";
}
sub show_installation_status {
say colored(['bright_yellow'], "Setting up your fish farm..."); sleep(1);
say colored(['bright_green'], " Feeder installed and switched on!"); sleep(1);
say colored(['bright_green'], " Water level maintiner installed and switched on!"); sleep(1);
say colored(['bright_green'], " Water filter installed and switched on!"); sleep(1);
say colored(['bright_yellow'], " Setting up water condition monitor..."); sleep(1);
say colored(['bright_green'], " Water condition monitor installed!"); sleep(1);
say colored(['bright_yellow'], " Oxygen maintainer installed & connected to water condition monitor..."); sleep(1);
say colored(['bright_green'], " Water condition monitor switched on!"); sleep(1);
say colored(['bold bright_blue'], "Your fish farm is ready!");
say "";
}
sub show_all_threshold {
my $ph_range = $water_monitor->ph_threshold;
my $temperature_range = $water_monitor->temperature_threshold;
say colored(['bold bright_magenta'], "Acceptable threshold/range of parameters:");
say " Min. DO level: ", $oxygen->DO_threshold, " mg/L";
say " pH: ", $ph_range->[0], "~", $ph_range->[1];
say " Temperature: ", $temperature_range->[0], "~", $temperature_range->[1], " C";
say " Max. Turbidity: ", $water_monitor->turbidity_threshold, " ntu";
say " Max. Waste Count: ", $water_filter->waste_count_threshold;
say " Min. Water level: ", $water_level->low_water_level_threshold, " m";
say "";
}
# besiyata d'shmaya
scripts/oxygen_maintainer.pl view on Meta::CPAN
#!/usr/bin/perl
use strict;
use warnings;
use 5.010;
use Acme::FishFarm::OxygenMaintainer;
my $oxygen = Acme::FishFarm::OxygenMaintainer->install( DO_generation_volume => 3 );
say "Oxygen maintainer installed!\n";
while ( "fish are using up oxygen" ) {
say "Current Oxygen Level: ", $oxygen->current_DO, " mg/L",
" (low: < ", $oxygen->DO_threshold, ")";
#say "Low Oxygen Level: ", $oxygen->DO_threshold, " mg/L";
if ( $oxygen->is_low_DO ) {
say "Fish status: Suffocating";
say " !! Low oxygen level!";
say "Pumping ", $oxygen->oxygen_generation_volume, " mg/L of oxygen into the water..." ;
$oxygen->generate_oxygen;
} else {
say "Fish status: Happy";
}
#consume_oxygen( $oxygen, 3 ); # die
consume_oxygen( $oxygen, rand(2.5) );
sleep(3);
say "";
}
# must pass in a decimal
sub consume_oxygen {
my $o2_maintainer = shift;
my $consumed_oxygen = reduce_precision ( shift );
#$consumed_oxygen =~ /(\d+\.\d{3})/;
say "$consumed_oxygen mg/L of oxygen consumed...";
my $o2_remaining = $o2_maintainer->current_DO - $consumed_oxygen;
$o2_maintainer->current_DO( $o2_remaining );
}
sub reduce_precision {
my $sensor_reading = shift;
die "Please pass in a decimal value" if not $sensor_reading =~ /\./;
$sensor_reading =~ /(\d+\.\d{3})/;
$1;
}
scripts/water_filter.pl view on Meta::CPAN
use strict;
use warnings;
use 5.010;
use Acme::FishFarm qw( check_water_filter reduce_precision );
use Acme::FishFarm::WaterFiltration;
my $water_filter = Acme::FishFarm::WaterFiltration->install;
say "Water filter installed and switched on!\n";
while ( "Fish are living under the water..." ) {
check_water_filter( $water_filter, int (rand(150)), reduce_precision( rand(10) ) );
sleep(1);
say "";
}
=head1 use Acme::FishFarm's check_water_filter
sub check_water_filter {
my ( $water_filter, $current_reading ) = @_;
my $waste_threshold = $water_filter->waste_count_threshold;
$water_filter->current_waste_count( $current_reading );
print "Current Waste Count: ", $current_reading, " (high: >= ", $waste_threshold, ")\n";
scripts/water_level.pl view on Meta::CPAN
use strict;
use warnings;
use 5.010;
use Acme::FishFarm ":all";
use Acme::FishFarm::WaterLevelMaintainer;
my $water_level = Acme::FishFarm::WaterLevelMaintainer->install;
say "Water level maintainer installed and switched on!\n";
while ( "Fish are living under the water..." ) {
check_water_level( $water_level, reduce_precision(rand(8)) );
sleep(1);
say "";
}
=head1 use Acme::FishFarm's check_water_level
sub check_water_level {
my $water_level = shift;
my $current_reading = shift;
my $height_increase = $water_level->water_level_increase_height; # for output
my $water_level_threshold = $water_level->low_water_level_threshold;
$water_level->current_water_level( $current_reading ); # input by user
scripts/water_monitor.pl view on Meta::CPAN
use 5.010;
use Acme::FishFarm::WaterConditionMonitor;
use Acme::FishFarm::OxygenMaintainer;
my $water_monitor = Acme::FishFarm::WaterConditionMonitor->install;
my $oxygen = Acme::FishFarm::OxygenMaintainer->install( DO_generation_volume => 1.92 );
$water_monitor->add_oxygen_maintainer( $oxygen );
say "Water condition monitor installed...";
say "Oxygen maintainer installed and connected to water condition monitor...";
say "Water condition monitor switched on!";
say "";
# my $first_round = 1; # not applicable for manual input
while ( "fish are swimming happily" ) {
### DO
check_DO( $oxygen, reduce_precision( rand(8) ) );
# not applicable for manual input
#if ( $first_round ) {
# $first_round = 0;
#} else {
# consume_oxygen( $oxygen, 1.25 );
#}
say "";
### pH
check_pH( $water_monitor, 6.912 );
#check_pH( $water_monitor, 5.9 );
say "" ;
## temperature
#check_temperature( $water_monitor, 23 );
check_temperature( $water_monitor, 26 );
say "";
## turbidity
check_turbidity( $water_monitor, 120 );
#check_turbidity( $water_monitor, 190 );
say "";
# all LEDs
render_leds( $water_monitor );
#if ( $water_monitor->is_on_LED_DO ) {
# say " Low oxygen LED: up";
#}
say "";
# buzzers
render_buzzer( $water_monitor );
sleep(3);
say "-----------------------------";
}
# taken directly from oxygen_maintainer.pl
# these 2 subroutines are to be called manually, the check_* only checks the current condition
# must pass in a decimal
sub consume_oxygen {
my $o2_maintainer = shift;
my $consumed_oxygen = shift;
say "$consumed_oxygen mg/L of oxygen consumed...";
my $o2_remaining = $o2_maintainer->current_DO - $consumed_oxygen;
$o2_maintainer->current_DO( $o2_remaining );
}
sub reduce_precision {
my $sensor_reading = shift;
die "Please pass in a decimal value" if not $sensor_reading =~ /\./;
$sensor_reading =~ /(\d+\.\d{3})/;
$1;
}
sub check_DO {
my ( $oxygen, $current_reading ) = @_;
my $DO_threshold = $oxygen->DO_threshold;
$oxygen->current_DO( $current_reading );
$oxygen->is_low_DO;
say "Current Oxygen Level: ", $current_reading, " mg/L",
" (low: < ", $DO_threshold, ")";
if ( $oxygen->is_low_DO ) {
say " !! Low oxygen level!";
# commented ones are not applicable for manual input
#say "Pumping ", $oxygen->oxygen_generation_volume, " mg/L of oxygen into the water..." ;
#$oxygen->generate_oxygen;
} else {
say " Oxygen level is normal.";
}
}
sub check_pH {
my ( $water_monitor, $current_reading ) = @_;
my $ph_range = $water_monitor->ph_threshold;
$water_monitor->current_ph( $current_reading );
$water_monitor->ph_is_normal;
say "Current pH: ", $water_monitor->current_ph,
" (normal range: ", $ph_range->[0], "~", $ph_range->[1], ")";
if ( !$water_monitor->ph_is_normal ) {
say " !! Abnormal pH!";
} else {
say " pH is normal."
}
}
sub check_temperature {
my ( $water_monitor, $current_reading ) = @_;
my $temperature_range = $water_monitor->temperature_threshold;
$water_monitor->current_temperature( $current_reading );
$water_monitor->temperature_is_normal;
say "Current temperature: ", $water_monitor->current_temperature, " C",
" (normal range: ", $temperature_range->[0], " C ~ ", $temperature_range->[1], " C)";
if ( !$water_monitor->temperature_is_normal ) {
say " !! Abnormal temperature!";
} else {
say " Temperature is normal."
}
}
sub check_turbidity {
my ( $water_monitor, $current_reading ) = @_;
my $turbidity_threshold = $water_monitor->turbidity_threshold;
$water_monitor->current_turbidity( $current_reading );
say "Current Turbidity: ", $water_monitor->current_turbidity, " ntu",
" (dirty: > ", $turbidity_threshold, ")";
if ( $water_monitor->water_dirty ) {
say " !! Water is dirty!";
} else {
say " Water is still clean.";
}
}
sub render_leds {
my $water_monitor = shift;
# must check condition first! If not it won't work
$water_monitor->ph_is_normal;
$water_monitor->temperature_is_normal;
$water_monitor->lacking_oxygen;
$water_monitor->water_dirty;
say "Total LEDs up: ", $water_monitor->lighted_LED_count;
if ( $water_monitor->is_on_LED_pH ) {
say " pH LED: on";
} else {
say " pH LED: off";
}
if ( $water_monitor->is_on_LED_temperature ) {
say " Temperature LED: on";
} else {
say " Temperature LED: off";
}
if ( $water_monitor->is_on_LED_DO ) {
say " Low DO LED: on";
} else {
say " Low DO LED: off";
}
if ( $water_monitor->is_on_LED_turbidity ) {
say " Turbidity LED: on";
} else {
say " Turbidity LED: off";
}
}
sub render_buzzer {
my $water_monitor = shift;
#$water_monitor->_tweak_buzzers;
if ( $water_monitor->is_on_buzzer_long ) {
say "Long buzzer is on, water condition very critical!";
} elsif ( $water_monitor->is_on_buzzer_short ) {
say "Short buzzer is on, water condition is a bit worrying :|";
} else {
say "No buzzers on, what a peaceful moment."
}
}
# besiyata d'shmaya