Forum Software Ferduino code WaveMaker alternated with storm

WaveMaker alternated with storm  [SOLVED]


Post Number:#1 Post Mon Jun 09, 2014 9:30 am
Posts: 92
Topics: 10
Solve rating: 0
Joined: Sat May 17, 2014 9:03 am
Topics: 10
Age: 43
Gender: None specified
National Flag:
France
Hi
In my older arduino, i has modified wavemaker for an alternated and storm.

I tried to copy the code to put in place of mode 4 in Ferduino code and i have add the night mode.

i am newbie in devellopement arduino and I can not find "periodo"

but "periodo" is too long, how I can change it to 700, 800, 900, for an example

 else if(modo_selecionado == 4)
   switch (cmode){ 
     case 0: times = millis();
    value = int(128 + 127 * sin(2 * PI / periodo * times));
    Pump1PWM = 0;     
    Pump2PWM = value;
   if(value == 255){cmode = 1;} // при достижении уровня 253 - перейти к case 1
     break;
     
      case 1:
    times = millis();
    value = int(128 + 127 * sin(2 * PI / periodo * times));
     Pump1PWM = value;
     Pump2PWM = 0;
   if(value == 253){cmode = 2;} // при достижении значения уровня 253 - перейти к case 1   
    break;
 
    case 2: times = millis();
   value = int(128 + 127 * sin(2 * PI / periodo * times));
     Pump1PWM = 255;
     Pump2PWM = 0;   
  if(value == 100){cmode = 3;}
    break;
 
    case 3: times = millis();
   value = int(128 + 127 * sin(2 * PI / periodo * times));
      Pump1PWM = 0;
      Pump2PWM = 255;
  if(value == 100){cmode = 4;}
    break;
 
    case 4: times = millis();
   value = int(128 + 127 * sin(2 * PI / periodo * times));
     Pump1PWM = value;
     Pump2PWM = 0;
  if(value == 255){cmode = 5;}
    break;
 
    case 5: times = millis();
   value = int(128 + 127 * sin(2 * PI / periodo * times));
     Pump1PWM = 0;
     Pump2PWM = value;
  if(value == 255){cmode = 6;}   
    break;
 
    case 6: times = millis();
   value = int(128 + 127 * sin(2 * PI / periodo * times));
     Pump1PWM = 255;
     Pump2PWM = 255;
  if(value == 252){cmode = 7;}
    break;
   
    case 7: times = millis();
   value = int(128 + 127 * sin(2 * PI / periodo * times));
     Pump1PWM = 0;  // 255
     Pump2PWM = 0;  // 255
  if(value == 20){cmode = 0;}
    break;
   }
 
  else if(modo_selecionado == 5)
{
 Pump1PWM = Pump1PWM_temp;
 Pump2PWM = Pump2PWM_temp;
}
  if(Pump1PWM > 255)
  {
    Pump1PWM = 255;
  }
  else if(Pump1PWM < 0)
  {
    Pump1PWM = 0;
  }
  else if(Pump2PWM > 255)
  {
    Pump2PWM = 255;
  }
  else if(Pump2PWM < 0)
  {
    Pump2PWM = 0;
  }
if((bled_out == 0) && (wled_out == 0) && (rbled_out  == 0) && (rled_out == 0))
  {
  analogWrite(wavemaker1, int(Pump1PWM * 0.50));
  analogWrite(wavemaker2, int(Pump2PWM * 0.50));
  }
  else
  {
  analogWrite(wavemaker1, Pump1PWM );
  analogWrite(wavemaker2, Pump2PWM );   
  }
}


Thank you in advanced

Post Number:#2 Post Mon Jun 09, 2014 9:48 am
Posts: 1699
Topics: 38
Images: 301
Solve rating: 233
Joined: Mon Mar 03, 2014 5:59 pm
Topics: 38
Age: 39
Location: São Paulo
Gender: Male
National Flag:
Brazil

Hi!

Here you can change the step and the interval:

https://github.com/FernandoGarcia/Fedui ... .ino#L1061

          duracao -= 1000;
          if(duracao < 1000)
          {
            duracao = 5000;
          }


Example:

          duracao -= 100;
          if(duracao < 100)
          {
            duracao = 5000;
          }


Best regards.
Post your doubts on forum because it can help another user too. Just PM me for support if it's absolutely necessary.

Post Number:#3 Post Mon Jun 09, 2014 10:22 am
Posts: 92
Topics: 10
Solve rating: 0
Joined: Sat May 17, 2014 9:03 am
Topics: 10
Age: 43
Gender: None specified
National Flag:
France
thank again ^:)^

I have changed "duraco" par "periodo" in Procesmytouch.ino

else if(modo_selecionado == 4)
      {
        if ((x>=peRB[0]) && (x<=peRB[2]) && (y>=peRB[1]) && (y<=peRB[3]))  // Duração do intervalo -
        {
          //waitForIt(peRB[0], peRB[1], peRB[2], peRB[3]);
          periodo -= 100;
          if(periodo < 100)
          {
            periodo = 5000;
          }
          waveScreen();
        }       
        else if ((x>=peRC[0]) && (x<=peRC[2]) && (y>=peRC[1]) && (y<=peRC[3]))  // intervalo +
        {
          //waitForIt(peRC[0], peRC[1], peRC[2], peRC[3]);
          periodo += 1000;
          if(periodo > 5000)
          {
            periodo = 1000;
          }
          waveScreen();
        }       


and changed in L_Menu Modo 4 =periodo

 if((modo_selecionado == 1) || (modo_selecionado == 2)|| (modo_selecionado == 4))
  {
    myGLCD.print("     ", 75, 145);
    myGLCD.printNumI(periodo, 75, 145);
  }
  else if((modo_selecionado == 3)) 
  {
    myGLCD.print("    ", 85, 150);
    myGLCD.printNumI(duracao, 85, 150); 
  }


The difficult for me, it's for one fonction they are three ways: fonction, graphic and touch, that my loses some ~x(

Post Number:#4 Post Mon Jun 09, 2014 10:37 am
Posts: 1699
Topics: 38
Images: 301
Solve rating: 233
Joined: Mon Mar 03, 2014 5:59 pm
Topics: 38
Age: 39
Location: São Paulo
Gender: Male
National Flag:
Brazil

You need change here also:

 
        periodo += 1000;
          if(periodo > 5000)
          {
            periodo = 1000;
          }
Post your doubts on forum because it can help another user too. Just PM me for support if it's absolutely necessary.

Post Number:#5 Post Mon Jun 09, 2014 11:07 am
Posts: 92
Topics: 10
Solve rating: 0
Joined: Sat May 17, 2014 9:03 am
Topics: 10
Age: 43
Gender: None specified
National Flag:
France
No When i changed also "duraco" by "periodo" touch is ok, but but the display does not follow.

when i changed L_menu, it's good

Post Number:#6 Post Mon Jun 09, 2014 11:18 am
Posts: 1699
Topics: 38
Images: 301
Solve rating: 233
Joined: Mon Mar 03, 2014 5:59 pm
Topics: 38
Age: 39
Location: São Paulo
Gender: Male
National Flag:
Brazil

I don't understand what you mean.

Some images can help.
Post your doubts on forum because it can help another user too. Just PM me for support if it's absolutely necessary.

Post Number:#7 Post Mon Jun 09, 2014 11:21 am
Posts: 92
Topics: 10
Solve rating: 0
Joined: Sat May 17, 2014 9:03 am
Topics: 10
Age: 43
Gender: None specified
National Flag:
France
nothing is good

I think it works

Thank you

Post Number:#8 Post Mon Jun 09, 2014 1:34 pm
Posts: 92
Topics: 10
Solve rating: 0
Joined: Sat May 17, 2014 9:03 am
Topics: 10
Age: 43
Gender: None specified
National Flag:
France
There is a bug in the code that I added the switch case 0: to case1: to case 2: .... do not work, it's don't switch

Can you take a look that if you see a problem ? "value== 255"



 else if(modo_selecionado == 4)
   switch (cmode){ 
     case 0: times = millis();
    value = int(128 + 127 * sin(2 * PI / periodo * times));
    Pump1PWM = 0;     
    Pump2PWM = value;
   if(value == 255){cmode = 1;} //
     break;
     
      case 1:
    times = millis();
    value = int(128 + 127 * sin(2 * PI / periodo * times));
     Pump1PWM = value;
     Pump2PWM = 0;
   if(value == 253){cmode = 2;} // при достижении значения уровня 253 - перейти к case 1   
    break;
 
    case 2: times = millis();
   value = int(128 + 127 * sin(2 * PI / periodo * times));
     Pump1PWM = 255;
     Pump2PWM = 0;   
  if(value == 100){cmode = 3;}
    break;
 

Post Number:#9 Post Mon Jun 09, 2014 1:46 pm
Posts: 1699
Topics: 38
Images: 301
Solve rating: 233
Joined: Mon Mar 03, 2014 5:59 pm
Topics: 38
Age: 39
Location: São Paulo
Gender: Male
National Flag:
Brazil

This is a question of probability.

What's the probability of "value" be 255 to this equation?

value = int(128 + 127 * sin(2 * PI / periodo * times));
Post your doubts on forum because it can help another user too. Just PM me for support if it's absolutely necessary.

Post Number:#10 Post Mon Jun 09, 2014 1:54 pm
Posts: 92
Topics: 10
Solve rating: 0
Joined: Sat May 17, 2014 9:03 am
Topics: 10
Age: 43
Gender: None specified
National Flag:
France
Good question, i don't know, the original value=253, but i want Pump1PWM for 20 minutes after Pump2PWM for 20 minutes ...
On Jarduino was work but equation is different "value = 128+127*cos(2*PI/periode*(times-(starttime+startvalue))); "

Post Number:#11 Post Mon Jun 09, 2014 3:03 pm
Posts: 1699
Topics: 38
Images: 301
Solve rating: 233
Joined: Mon Mar 03, 2014 5:59 pm
Topics: 38
Age: 39
Location: São Paulo
Gender: Male
National Flag:
Brazil

The probability is 1 / 127 or 0.7874 %. ;)
Post your doubts on forum because it can help another user too. Just PM me for support if it's absolutely necessary.

Post Number:#12 Post Mon Jun 09, 2014 3:11 pm
Posts: 92
Topics: 10
Solve rating: 0
Joined: Sat May 17, 2014 9:03 am
Topics: 10
Age: 43
Gender: None specified
National Flag:
France
yes it's very difficult but i have tested with value ==100, it's same problem

i tried with millis but it's difficult for me.

if((millis() - temps) > 1800000) ... ~x(

 else if(modo_selecionado == 4)
   switch (cmode){ 
     case 0: times = millis();
    value = int(128 + 127 * sin(2 * PI / periodo * times));
    Pump1PWM = 0;     
    Pump2PWM = value;
   if((millis() - temps) > 1800000){cmode = 1;}
   temps = millis();
   break;
     
      case 1:
    times = millis();
    value = int(128 + 127 * sin(2 * PI / periodo * times));
     Pump1PWM = value;
     Pump2PWM = 0;
   if((millis() - temps) > 1800000){cmode = 2;}
    temps = millis();
    break;

Post Number:#13 Post Wed Jun 11, 2014 5:08 pm
Posts: 92
Topics: 10
Solve rating: 0
Joined: Sat May 17, 2014 9:03 am
Topics: 10
Age: 43
Gender: None specified
National Flag:
France
Hi, if anyone can help me ?

thank you

Post Number:#14 Post Wed Jun 11, 2014 5:17 pm
Posts: 1699
Topics: 38
Images: 301
Solve rating: 233
Joined: Mon Mar 03, 2014 5:59 pm
Topics: 38
Age: 39
Location: São Paulo
Gender: Male
National Flag:
Brazil

Hi!

Try this:

   if((millis() - temps) > 1800000)
{
 cmode = 1;
  temps = millis();
}
   break;


You need wait 30 minutes to see the result or change the interval.

Best regards.
Post your doubts on forum because it can help another user too. Just PM me for support if it's absolutely necessary.

Post Number:#15 Post Wed Jun 11, 2014 6:05 pm
Posts: 92
Topics: 10
Solve rating: 0
Joined: Sat May 17, 2014 9:03 am
Topics: 10
Age: 43
Gender: None specified
National Flag:
France
Hi Fernando

Thank you

I tried but don't switch to case 1:
void Wavemaker()
{
  long temps = millis();
  int cmode = 0; 
  int value = 0;
  long times = millis();


 else if(modo_selecionado == 4)
   switch (cmode){ 
    case 0:
    value = int(128 + 127 * sin(2 * PI / periodo * times));
    Pump1PWM = 0;     
    Pump2PWM = value;
   if((millis() - temps) > 18000)
     {
     cmode = 1;
     temps = millis();
     }
     break;
     
    case 1:
    value = int(128 + 127 * sin(2 * PI / periodo * times));
    Pump1PWM = value;
    Pump2PWM = 0;
   if((millis() - temps) > 18000)
     {
     cmode = 0;
     temps = millis();
     }
     break;
   }


I tried several way and it never switches !!!!

Post Number:#16 Post Wed Jun 11, 2014 6:10 pm
Posts: 1699
Topics: 38
Images: 301
Solve rating: 233
Joined: Mon Mar 03, 2014 5:59 pm
Topics: 38
Age: 39
Location: São Paulo
Gender: Male
National Flag:
Brazil

You can't put this variable as local.

long temps = millis();


Should be global variable.

Put here:

https://github.com/FernandoGarcia/Fedui ... a.ino#L886

After:

byte Pump2PWM = 0;
Post your doubts on forum because it can help another user too. Just PM me for support if it's absolutely necessary.

Post Number:#17 Post Wed Jun 11, 2014 6:16 pm
Posts: 92
Topics: 10
Solve rating: 0
Joined: Sat May 17, 2014 9:03 am
Topics: 10
Age: 43
Gender: None specified
National Flag:
France
this variable also ?

int cmode = 0;
Last edited by Sueur Aurelien on Wed Jun 11, 2014 6:19 pm, edited 1 time in total.

Post Number:#18 Post Wed Jun 11, 2014 6:18 pm
Posts: 1699
Topics: 38
Images: 301
Solve rating: 233
Joined: Mon Mar 03, 2014 5:59 pm
Topics: 38
Age: 39
Location: São Paulo
Gender: Male
National Flag:
Brazil

this variable too ?

int cmode = 0;



Yes.
Post your doubts on forum because it can help another user too. Just PM me for support if it's absolutely necessary.

Post Number:#19 Post Wed Jun 11, 2014 6:23 pm
Posts: 92
Topics: 10
Solve rating: 0
Joined: Sat May 17, 2014 9:03 am
Topics: 10
Age: 43
Gender: None specified
National Flag:
France
YEAHHHH!!!!! :-bd

A BIG THANK YOU

it's been several days that I break my head on it

Post Number:#20 Post Wed Jun 11, 2014 6:28 pm
Posts: 1699
Topics: 38
Images: 301
Solve rating: 233
Joined: Mon Mar 03, 2014 5:59 pm
Topics: 38
Age: 39
Location: São Paulo
Gender: Male
National Flag:
Brazil

Cool!

Some suggestions of good practice of programming.

int cmode = 0;
int value = 0;


"cmode" and "value" never will be higher than 255 so use it:

byte cmode = 0;
byte value = 0;
Post your doubts on forum because it can help another user too. Just PM me for support if it's absolutely necessary.

Next



Return to Ferduino code





Who is online

Users viewing this topic: No registered users and 1 guest

cron