No google pesquisa por "wp-40 reef angel", começa por "forum.reefan..."
Sorry estou no telemovel e assim é mais facil

#include <Arduino.h>
/*
Software para controlar bomba WP-40 - 1 canal
Arduino
Bomba WP-40
Transformador
Reset do Arduino faz a função Feed(Para a bomba por 5m) e reinicializa passados esses 5m.
*/
// constantes
//const int ModoFuncionamento = 1;
const int maxModos = 6;
const int buttonPin = 7;
const int buttonPinF = 8;
const int PWMPinLPF = 3;
const int PinLed1 = 10;
const int PinLed2 = 11;
const int PinLed3 = 12;
const int PinLed4 = 13;
// Variaveis:
int ModoFuncionamento = 1;
int ModoFuncionamentoAnt = 0;
int EstadoPulse = 0;
long previousMillis = 0;
unsigned long currentMillis = millis();
int buttonState = 0;
int buttonStateF = 0;
//Inicio Funções
void limpaLeds()
{
digitalWrite(PinLed1, LOW);
digitalWrite(PinLed2, LOW);
digitalWrite(PinLed3, LOW);
digitalWrite(PinLed4, LOW);
}
void activaLeds()
{
switch (ModoFuncionamento){
case 1:
digitalWrite(PinLed1, HIGH);
break;
case 2:
digitalWrite(PinLed2, HIGH);
break;
case 3:
digitalWrite(PinLed3, HIGH);
break;
case 4:
digitalWrite(PinLed4, HIGH);
break;
case 5:
digitalWrite(PinLed1, HIGH);
digitalWrite(PinLed2, HIGH);
break;
case 6:
digitalWrite(PinLed1, HIGH);
digitalWrite(PinLed4, HIGH);
break;
case 7:
digitalWrite(PinLed1, HIGH);
digitalWrite(PinLed2, HIGH);
digitalWrite(PinLed3, HIGH);
digitalWrite(PinLed4, HIGH);
break;
}
}
void verificaPushButton()
{
buttonState = digitalRead(buttonPin);
buttonStateF = digitalRead(buttonPinF);
}
void timer(long milliSegundos)
{
int sai = 0;
if(buttonState == HIGH){
return;
}
do {
currentMillis = millis();
verificaPushButton();
if(currentMillis - previousMillis > milliSegundos) {
previousMillis = currentMillis;
sai = 1;
}
} while (buttonState == LOW && buttonStateF == LOW && sai == 0);
}
/*
Modo a utilizar dentro do ReefCrazy - Faz nX Pulse
*/
void PulseSingle(int Imax, int Imin, int MiliSegundos, int NrTimes)
{
int Contador = 0;
int sai = 0;
if(buttonState == HIGH || buttonStateF == HIGH){
return;
}
do {
Contador = Contador + 1;
analogWrite(PWMPinLPF, Imax);
timer(MiliSegundos);
if(buttonState == HIGH || buttonStateF == HIGH){
return;
}
analogWrite(PWMPinLPF, Imin);
timer(MiliSegundos);
if(buttonState == HIGH || buttonStateF == HIGH){
return;
}
}
while (Contador <= NrTimes && buttonState == LOW);
}
/* Pulse(Imax, Imin, MilSegundos) - Modo 1
Recebe de entrada:
Imax: Intensidade máxima do Pulse
Imin: Intensidade Minima depois do pulse
MilSegundos: Nr de MiliSegundos de intervalo entre intesidade Máxima e Minima
O Objectivo é variar directo, sem incremento gradual entre a velocidade máxima e velocidade minima pelo nr de segundos indicado
Ex:
Pulse(255, 100, 500)
A Bomba deveria começar a cerca de 40%(100/255) durante 0,5 Segundos, em seguida faz 100% durante 0,5 Segundos
*/
void Pulse(int Imax, int Imin, int MiliSegundos)
{
if(buttonState == HIGH || buttonStateF == HIGH){
return;
}
PulseSingle(Imax, Imin, MiliSegundos, 5);
}
/* RampUp(IntMin, IntMax, Increm, Percent) - Modo 2
Recebe de entrada:
IntMin: Intensidade Inicial
IntMax: Intensidade Final
Increm: Nr de MiliSegundos de intervalo entre intesidade
O Objectivo é variar directo com incremento gradual entre a intensidade minima e máxima, com Increm segundos de intervalo entre o incremento
Ex:
RampUp(50, 225, 500, 15)
A Bomba faria:
Começa nos 20% e fica durante 0,5 Seg
Incrementa 15 ao PWM(65/255) ficando a 25% durante 0,5 Seg
Vai incrementando 5% durante 0,5 Seg até chegar a 88%(225/255)
*/
void RampUp(int IntMin, int IntMax, int Increm, int Percent) {
int ValorPwm = IntMin;
if(buttonState == HIGH || buttonStateF == HIGH){
return;
}
analogWrite(PWMPinLPF, ValorPwm);
do
{
currentMillis = millis();
if(currentMillis - previousMillis > Increm) {
previousMillis = currentMillis;
if(ValorPwm > IntMax) {
ValorPwm = IntMax;
}
analogWrite(PWMPinLPF, ValorPwm);
ValorPwm = ValorPwm + Percent;
}
verificaPushButton();
if(buttonState == HIGH || buttonStateF == HIGH){
return;
}
}
while(ValorPwm < IntMax && ValorPwm >= IntMin);
}
/* RampDown(IntMin, IntMax, Increm, Percent) - Modo 2
Recebe de entrada:
IntMin: Intensidade Inicial
IntMax: Intensidade Final
Increm: Nr de MiliSegundos de intervalo entre intesidade
O Objectivo é variar directo com incremento gradual entre a intensidade minima e máxima, com Increm segundos de intervalo entre o incremento
Ex:
RampUp(50, 225, 500, 15)
A Bomba faria:
Começa nos 20% e fica durante 0,5 Seg
Incrementa 15 ao PWM(65/255) ficando a 25% durante 0,5 Seg
Vai incrementando 5% durante 0,5 Seg até chegar a 88%(225/255)
*/
void RampDown(int IntMin, int IntMax, int Increm, int Percent) {
int ValorPWM = IntMax;
if(buttonState == HIGH || buttonStateF == HIGH){
return;
}
analogWrite(PWMPinLPF, ValorPWM);
do
{
currentMillis = millis();
if(currentMillis - previousMillis > Increm) {
previousMillis = currentMillis;
if(ValorPWM < IntMin) {
ValorPWM = IntMin;
}
analogWrite(PWMPinLPF, ValorPWM);
ValorPWM = ValorPWM - Percent;
}
verificaPushButton();
if(buttonState == HIGH || buttonStateF == HIGH){
return;
}
}
while(ValorPWM <= IntMax && ValorPWM > IntMin);
}
/* ReefCrazy(IntMin, IntMax, SegMud) - Modo 3
Recebe de Entrada:
Intensidade Minima: Intensidade minima a que a bomba Roda
Intensidade Máxima: Intensidade Máxima a que a bomba roda
Segundos entre as mudanças: Segundos até mudança de modo aleatório
*/
void ReefCrazy(int IntMin, int IntMax, int SegMud)
{
int RNumber = random(IntMin, IntMax);
int MidleR = (IntMin + IntMax) / 2;
if(buttonState == HIGH || buttonStateF == HIGH){
return;
}
if(RNumber > (MidleR - 20) && RNumber < (MidleR + 20)) {
PulseSingle(240, 100, 500, 3);
}
if(RNumber > MidleR) {
RampDown(IntMin, MidleR, 500, 15);
}
else
{
RampUp(MidleR, IntMax, 500, 15);
}
RNumber = random(IntMin, IntMax);
MidleR = (IntMin + IntMax) / 2;
}
/* Modo 4
Sem parametros de entrada, sobe dos 0 aos 125PWM, faz Pulse 2X, continua a subir aos 255;
Começa a descer dos 255 até 125, faz pulse, e continua até 0;
*/
void JumpingHorse()
{
if(buttonState == HIGH || buttonStateF == HIGH){
return;
}
RampUp(100, 175, 200, 5);
PulseSingle(255, 150, 500, 2);
RampUp(175, 255, 200, 5);
RampDown(175, 255, 200, 5);
PulseSingle(255, 150, 500, 2);
RampDown(100, 175, 200, 5);
}
/* Modo 5
- Nutrient Export Mode(5 Pulses a 0,5s, muito pequenos, mais 5 maiores, pulse grande para fazer onda, e o processo de pulses inverso).
*/
void NutrientZero()
{
if(buttonState == HIGH || buttonStateF == HIGH){
return;
}
RampUp(125, 240, 300, 15);
timer(1000);
RampDown(125, 240, 300, 15);
PulseSingle(125, 225, 500, 8);
}
/* Modo Desligar - Modo 6 Para fazer por exemplo manutenção ao aquario, fica preparado para quem usar botão*/
void Desligar()
{
if(buttonState == HIGH || buttonStateF == HIGH){
return;
}
analogWrite(PWMPinLPF, 0);
}
void alimentar(long milliSegundos)
{
if(buttonState == HIGH || buttonStateF == HIGH){
return;
}
analogWrite(PWMPinLPF, 0);
timer(milliSegundos);
}
void setup()
{
// Inicializa PWM
Serial.begin(9600);
pinMode(PWMPinLPF, OUTPUT);
pinMode(PinLed1, OUTPUT);
pinMode(PinLed2, OUTPUT);
pinMode(PinLed3, OUTPUT);
pinMode(PinLed4, OUTPUT);
pinMode(buttonPin, INPUT);
pinMode(buttonPinF, INPUT);
previousMillis = millis();
limpaLeds();
activaLeds();
}
void loop(){
if(buttonState == HIGH){
if(ModoFuncionamento >= maxModos) {
ModoFuncionamento = 1;
} else {
ModoFuncionamento = ModoFuncionamento + 1;
}
limpaLeds();
activaLeds();
buttonState = LOW;
delay(200);
} else {
verificaPushButton();
}
//Verifica estado de FEED
if(buttonStateF == HIGH){
if(ModoFuncionamento == 7)
{
ModoFuncionamento = ModoFuncionamentoAnt;
} else {
ModoFuncionamentoAnt = ModoFuncionamento;
ModoFuncionamento = 7;
}
limpaLeds();
activaLeds();
buttonStateF = LOW;
delay(200);
}
if (ModoFuncionamento == 1) {
Pulse(255, 150, 300);
}
if (ModoFuncionamento == 2) {
RampUp(100, 245, 500, 15);
RampDown(100, 245, 500, 15);
}
if (ModoFuncionamento == 3) {
ReefCrazy(100, 245, 500);
}
if (ModoFuncionamento == 4) {
JumpingHorse();
}
if (ModoFuncionamento == 5) {
NutrientZero();
}
if (ModoFuncionamento == 6) {
Desligar();
}
if (ModoFuncionamento == 7) {
alimentar(300000);
ModoFuncionamento = ModoFuncionamentoAnt;
limpaLeds();
activaLeds();
}
}