Show Posts
Pages: 1 2 [3] 4 5 ... 8
31  Using Arduino / Programming Questions / Re: anyone hear of concurrency.cc on: February 25, 2012, 07:18:24 am
Update
They have
All open source
PDF book very well written explains everything.
No community no one to ask Questions, they do have a mailing list I signed up for it.
You have to use their IDE seems a little better to me, it gives you more features.It couldn't find my com port had to tell it, found that strange with all the cool features and it couldn't do that, not a big deal though.
How it works is you load their software on the Arduino, then you can write your scketch normal like. It
creates an extra long scketch you don't see. You need to load it every time you upload, a simple push of a button.
They are selling these custom boards I don't get the point of, the magic is in the software, and it loaded on my arduino uno instant like.
Don't quote me but it was something like 36 same time way more then then your board has.
Easy peasy had two leds blinking same time in under a minute. Don't think this will work for me, I'm using optical relays and Off is On so the term Blink is a no go. Have fun

32  Using Arduino / Programming Questions / anyone hear of concurrency.cc on: February 24, 2012, 01:36:53 pm
Found the site, and I'm going to try it, I needed simple multitasking and I couldn't figure out the QP state machine, way too complicated.
Seems like with simple code you can blink 2 or more things the same time on your arduino.
Only thing  is I'm not sure of, trying to blink them for like min, hours or weeks also I read someplace it maxes out at 45 days not sure what that means. Looks cool though


Code:
PROC main ()
2 PAR
3 blink (12 , 500)
4 blink (11 , 500)

33  Using Arduino / Programming Questions / Re: whats wrong on: February 22, 2012, 01:26:25 pm
Tried this still no go, thanks for the help by the way.
I do want it firing up at 8-9 so that's why its like this.
either end at 9 or continue on until the end where it loops and end there
little over my head but hopefully not too far.

Code:
//  Some macros for defining time intervals in milliseconds
#define seconds_in_ms(s) ((s)*1000UL)
#define minutes_in_ms(m) ((m)*60UL*1000UL)
#define hours_in_ms(h)   ((h)*60UL*60UL*1000UL)
#define days_in_ms(d)    ((d)*24UL*60UL*60UL*1000UL)
#define weeks_in_ms(w)   ((w)*7UL*24UL*60UL*60UL*1000UL)
#define PHIN  A0
unsigned long CycleStartTime = 0;
unsigned long LastTaskTime = 0;
unsigned long CurrentTaskInterval = 0;
unsigned Task = 3;


void setup()
{
 
pinMode(2, OUTPUT);  //PH down
pinMode(3, OUTPUT);  //B nutrient solution
pinMode(4, OUTPUT);  //A nutrient solution
pinMode(5, OUTPUT);  //Drain pump
pinMode(6, OUTPUT);  //Solenoid Valve
pinMode(7, OUTPUT);  //Nutrient Heater
pinMode(8, OUTPUT);  //Not used Future Nutrient/PH contoller

digitalWrite(2, HIGH);  //PH down off
digitalWrite(3, HIGH);  //B nutrient solution off
digitalWrite(4, HIGH);  //A nutrient solution off
digitalWrite(5, HIGH);  //Drain pump off
digitalWrite(6, HIGH);  //Solenoid Valve off
digitalWrite(7, HIGH);  //Nutrient Heater off
}

void loop()

{

  unsigned long currentTime = millis();

  // If the time has not yet come to perform a task
  if (currentTime - LastTaskTime >= CurrentTaskInterval)
  LastTaskTime = currentTime;

  switch (Task)
  {
  case 0:
    CycleStartTime = currentTime;  // Remember this time

   digitalWrite(5,LOW);   // set the drain pump on flush

    CurrentTaskInterval = minutes_in_ms(16);
    break;

  case 1:
digitalWrite(5,HIGH);   // set the drain pump off flush
digitalWrite(6,LOW); // set the Solenoid Valve on flush
  CurrentTaskInterval = minutes_in_ms(16);
 break;

 case 2:
digitalWrite(6,HIGH); // set the Solenoid Valve off flush
digitalWrite(7,LOW); // set the Nutrient Heater on flush
    CurrentTaskInterval = hours_in_ms(1);
 break;

 case 3:
digitalWrite(5,LOW);   // set the drain pump on
digitalWrite(7,HIGH); // set the Nutrient Heater off
  CurrentTaskInterval = minutes_in_ms(16);
 break;

  case 4:
digitalWrite(5,HIGH);   // set the drain pump off
digitalWrite(6,LOW); // set the Solenoid Valve on
digitalWrite(2,LOW);  // set the PH down on
digitalWrite(3,LOW); // set the B nutrient solution on
digitalWrite(4,LOW); // set the A nutrient solution on
  CurrentTaskInterval = seconds_in_ms(10);
 break;


case 5:
digitalWrite(2,HIGH);  // set the PH down off
digitalWrite(6,LOW); // set the Solenoid Valve on
digitalWrite(3,LOW); // set the B nutrient solution on
digitalWrite(4,LOW); // set the A nutrient solution on
  CurrentTaskInterval = minutes_in_ms(6);
break;


case 6:
digitalWrite(3,HIGH); // set the B nutrient solution off
digitalWrite(6,LOW); // set the Solenoid Valve on
digitalWrite(4,LOW); // set the A nutrient solution on
    CurrentTaskInterval = minutes_in_ms(5.04);
break;


case 7:
digitalWrite(4,HIGH); // set the A nutrient solution off
digitalWrite(6,LOW); // set the Solenoid Valve on
    CurrentTaskInterval = minutes_in_ms(5);
break;


case 8:
digitalWrite(6,HIGH); // set the Solenoid Valve off
digitalWrite(7,LOW); // set the Nutrient Heater on
digitalWrite(8,HIGH); // set the Future Nutrient/PH contoller

//pHduino avaerage routine, very effective for smoothing the readings
//alternatively you could perform software pass filtering here as well.
unsigned int readADC(int channel, unsigned reading_time)
{ double d;
int i;
unsigned long t0_us;
d = 0.0;
i = 0;
t0_us = micros();
while ((micros()-t0_us)<reading_time)
{ i++;
d += analogRead(channel);
}
d /= i;
return (unsigned int)(d);
}

show_pH(void)
{ int phRaw;
float phTmp, phOut, phMiliVolts;
if (Serial.available() )
{
}
phRaw = readADC(PHIN, 16666);    //Our averaged raw ADC value over ~ a single 60hz cycle
phTmp = (5*(float)phRaw)/1023;   //Convert reading into a voltage based on a 5v reference
phMiliVolts = phTmp * 1000;      //convert to milivolts
phTmp = (2500-phMiliVolts)/5.25; //Since our circuit contains an initial gain, we must remove it here
phOut = 7-(phTmp/59.16);            //ph is the numbers of "steps" from 7 (a step = mV/steps_per_mV)
Serial.print("ADC1 Raw: ");
Serial.println(phRaw);
Serial.print("ADC1 Milivolts: ");
Serial.println(phMiliVolts);
Serial.print("pH: ");
Serial.println(phOut);
delay(1000); //1 sec
}


CurrentTaskInterval = days_in_ms(1);
break;

case 9:
case 10:
case 11:
case 12:
case 13:
case 14:
case 15:
case 16:
case 17:
case 18:
case 19:
case 20:
case 21:
digitalWrite(6,LOW); // set the Solenoid Valve on/ top up
CurrentTaskInterval = seconds_in_ms(20);
digitalWrite(6,HIGH); // set the Solenoid Valve off/ top up
CurrentTaskInterval = days_in_ms(1);
break;

case 22:
// Start over again in one week from the START of the cycle
    LastTaskTime = CycleStartTime;
    CurrentTaskInterval = weeks_in_ms(1);
    Task = 0;   //starts loop
    break;
  }
}

34  Using Arduino / Programming Questions / Re: whats wrong on: February 22, 2012, 11:59:51 am
This works I didn't write it, I'm trying to integrate it into my program.
I'm getting an read ADC  was not declared in this scope
along with missing braces.

Code:
#define PHIN  A0

void setup() 
{
  pinMode(PHIN,INPUT);
  Serial.begin(9600);
  Serial.println("Welcome SW-02-010A");
}

void loop()
{
  int phRaw;
  float phTmp, phOut, phMiliVolts;
 
  if(Serial.available() )
  {

  }
  phRaw = readADC(PHIN, 16666);    //Our averaged raw ADC value over ~ a single 60hz cycle
  phTmp = (5*(float)phRaw)/1023;   //Convert reading into a voltage based on a 5v reference
  phMiliVolts = phTmp * 1000;      //convert to milivolts
  phTmp = (2500-phMiliVolts)/5.25; //Since our circuit contains an initial gain, we must remove it here
  phOut = 7-(phTmp/59.16);            //ph is the numbers of "steps" from 7 (a step = mV/steps_per_mV)
  Serial.print("ADC1 Raw: ");
  Serial.println(phRaw);
  Serial.print("ADC1 Milivolts: ");
  Serial.println(phMiliVolts);
  Serial.print("pH: ");
  Serial.println(phOut);
  delay(1000); //1 sec
}
//pHduino avaerage routine, very effective for smoothing the readings
//alternatively you could perform software pass filtering here as well.
unsigned int readADC(int channel, unsigned reading_time)
{
  double d;
  int i;
  unsigned long t0_us;
  d = 0.0;
  i = 0;
  t0_us = micros();
  while((micros()-t0_us)<reading_time){
    i++;
    d += analogRead(channel);
  }
  d /= i;
  return (unsigned int)(d); 
}

doing this
Code:
//  Some macros for defining time intervals in milliseconds
#define seconds_in_ms(s) ((s)*1000UL)
#define minutes_in_ms(m) ((m)*60UL*1000UL)
#define hours_in_ms(h)   ((h)*60UL*60UL*1000UL)
#define days_in_ms(d)    ((d)*24UL*60UL*60UL*1000UL)
#define weeks_in_ms(w)   ((w)*7UL*24UL*60UL*60UL*1000UL)
#define PHIN  A0
unsigned long CycleStartTime = 0;
unsigned long LastTaskTime = 0;
unsigned long CurrentTaskInterval = 0;
unsigned Task = 3;


void setup()
{
 
pinMode(2, OUTPUT);  //PH down
pinMode(3, OUTPUT);  //B nutrient solution
pinMode(4, OUTPUT);  //A nutrient solution
pinMode(5, OUTPUT);  //Drain pump
pinMode(6, OUTPUT);  //Solenoid Valve
pinMode(7, OUTPUT);  //Nutrient Heater
pinMode(8, OUTPUT);  //Not used Future Nutrient/PH contoller

digitalWrite(2, HIGH);  //PH down off
digitalWrite(3, HIGH);  //B nutrient solution off
digitalWrite(4, HIGH);  //A nutrient solution off
digitalWrite(5, HIGH);  //Drain pump off
digitalWrite(6, HIGH);  //Solenoid Valve off
digitalWrite(7, HIGH);  //Nutrient Heater off
}

void loop()

{

  unsigned long currentTime = millis();

  // If the time has not yet come to perform a task
  if (currentTime - LastTaskTime >= CurrentTaskInterval)
  LastTaskTime = currentTime;

  switch (Task)
  {
  case 0:
    CycleStartTime = currentTime;  // Remember this time

   digitalWrite(5,LOW);   // set the drain pump on flush

    CurrentTaskInterval = minutes_in_ms(16);
    break;

  case 1:
digitalWrite(5,HIGH);   // set the drain pump off flush
digitalWrite(6,LOW); // set the Solenoid Valve on flush
  CurrentTaskInterval = minutes_in_ms(16);
 break;

 case 2:
digitalWrite(6,HIGH); // set the Solenoid Valve off flush
digitalWrite(7,LOW); // set the Nutrient Heater on flush
    CurrentTaskInterval = hours_in_ms(1);
 break;

 case 3:
digitalWrite(5,LOW);   // set the drain pump on
digitalWrite(7,HIGH); // set the Nutrient Heater off
  CurrentTaskInterval = minutes_in_ms(16);
 break;

  case 4:
digitalWrite(5,HIGH);   // set the drain pump off
digitalWrite(6,LOW); // set the Solenoid Valve on
digitalWrite(2,LOW);  // set the PH down on
digitalWrite(3,LOW); // set the B nutrient solution on
digitalWrite(4,LOW); // set the A nutrient solution on
  CurrentTaskInterval = seconds_in_ms(10);
 break;


case 5:
digitalWrite(2,HIGH);  // set the PH down off
digitalWrite(6,LOW); // set the Solenoid Valve on
digitalWrite(3,LOW); // set the B nutrient solution on
digitalWrite(4,LOW); // set the A nutrient solution on
  CurrentTaskInterval = minutes_in_ms(6);
break;


case 6:
digitalWrite(3,HIGH); // set the B nutrient solution off
digitalWrite(6,LOW); // set the Solenoid Valve on
digitalWrite(4,LOW); // set the A nutrient solution on
    CurrentTaskInterval = minutes_in_ms(5.04);
break;


case 7:
digitalWrite(4,HIGH); // set the A nutrient solution off
digitalWrite(6,LOW); // set the Solenoid Valve on
    CurrentTaskInterval = minutes_in_ms(5);
break;


case 8:
digitalWrite(6,HIGH); // set the Solenoid Valve off
digitalWrite(7,LOW); // set the Nutrient Heater on
digitalWrite(8,HIGH); // set the Future Nutrient/PH contoller
{
  pinMode(PHIN,INPUT);
  Serial.begin(9600);
  Serial.println("Welcome SW-02-010A");
}
{
  int phRaw;
  float phTmp, phOut, phMiliVolts;
 
  if(Serial.available() )
  {

  }
  phRaw = readADC(PHIN, 16666);    //Our averaged raw ADC value over ~ a single 60hz cycle
  phTmp = (5*(float)phRaw)/1023;   //Convert reading into a voltage based on a 5v reference
  phMiliVolts = phTmp * 1000;      //convert to milivolts
  phTmp = (2500-phMiliVolts)/5.25; //Since our circuit contains an initial gain, we must remove it here
  phOut = 7-(phTmp/59.16);            //ph is the numbers of "steps" from 7 (a step = mV/steps_per_mV)
  Serial.print("ADC1 Raw: ");
  Serial.println(phRaw);
  Serial.print("ADC1 Milivolts: ");
  Serial.println(phMiliVolts);
  Serial.print("pH: ");
  Serial.println(phOut);
  delay(1000); //1 sec
}
//pHduino avaerage routine, very effective for smoothing the readings
//alternatively you could perform software pass filtering here as well.
unsigned int readADC(int channel, unsigned reading_time)
{
  double d;
  int i;
  unsigned long t0_us;
  d = 0.0;
  i = 0;
  t0_us = micros();
  while((micros()-t0_us)<reading_time){
    i++;
    d += analogRead(channel);
  }
  d /= i;
  return (unsigned int)(d); 
}
CurrentTaskInterval = days_in_ms(1);
break;

case 9:
case 10:
case 11:
case 12:
case 13:
case 14:
case 15:
case 16:
case 17:
case 18:
case 19:
case 20:
case 21:
digitalWrite(6,LOW); // set the Solenoid Valve on/ top up
CurrentTaskInterval = seconds_in_ms(20);
digitalWrite(6,HIGH); // set the Solenoid Valve off/ top up
CurrentTaskInterval = days_in_ms(1);
break;

case 22:
// Start over again in one week from the START of the cycle
    LastTaskTime = CycleStartTime;
    CurrentTaskInterval = weeks_in_ms(1);
    Task = 0;   //starts loop
    break;
  }
}
35  Using Arduino / Programming Questions / Re: whats wrong on: February 22, 2012, 10:58:51 am
Ok I don't want so sound dumb But I don't see it
It just doesn't like the
void setup()
{
Missing a brace probably, I buy that, but where?.
36  Using Arduino / Programming Questions / whats wrong on: February 21, 2012, 05:07:19 pm
wont compile why?
Code:
 
   //  Some macros for defining time intervals in milliseconds
#define seconds_in_ms(s) ((s)*1000UL)
#define minutes_in_ms(m) ((m)*60UL*1000UL)
#define hours_in_ms(h)   ((h)*60UL*60UL*1000UL)
#define days_in_ms(d)    ((d)*24UL*60UL*60UL*1000UL)
#define weeks_in_ms(w)   ((w)*7UL*24UL*60UL*60UL*1000UL)
#define PHIN  A0
unsigned long CycleStartTime = 0;
unsigned long LastTaskTime = 0;
unsigned long CurrentTaskInterval = 0;
unsigned Task = 3;


void setup()
{
  pinMode(PHIN,INPUT);
  Serial.begin(9600);
  Serial.println("Welcome SW-02-010A");

{


pinMode(2, OUTPUT);  //PH down
pinMode(3, OUTPUT);  //B nutrient solution
pinMode(4, OUTPUT);  //A nutrient solution
pinMode(5, OUTPUT);  //Drain pump
pinMode(6, OUTPUT);  //Solenoid Valve
pinMode(7, OUTPUT);  //Nutrient Heater
pinMode(8, OUTPUT);  //Not used Future Nutrient/PH contoller

digitalWrite(2, HIGH);  //PH down off
digitalWrite(3, HIGH);  //B nutrient solution off
digitalWrite(4, HIGH);  //A nutrient solution off
digitalWrite(5, HIGH);  //Drain pump off
digitalWrite(6, HIGH);  //Solenoid Valve off
digitalWrite(7, HIGH);  //Nutrient Heater off


void loop()

{

  unsigned long currentTime = millis();

  // If the time has not yet come to perform a task
  if (currentTime - LastTaskTime >= CurrentTaskInterval)
  LastTaskTime = currentTime;

  switch (Task)
  {
  case 0:
    CycleStartTime = currentTime;  // Remember this time

   digitalWrite(5,LOW);   // set the drain pump on flush

    CurrentTaskInterval = minutes_in_ms(16);
    break;

  case 1:
digitalWrite(5,HIGH);   // set the drain pump off flush
digitalWrite(6,LOW); // set the Solenoid Valve on flush
  CurrentTaskInterval = minutes_in_ms(16);
 break;

 case 2:
digitalWrite(6,HIGH); // set the Solenoid Valve off flush
digitalWrite(7,LOW); // set the Nutrient Heater on flush
    CurrentTaskInterval = hours_in_ms(1);
 break;

 case 3:
digitalWrite(5,LOW);   // set the drain pump on
digitalWrite(7,HIGH); // set the Nutrient Heater off
  CurrentTaskInterval = minutes_in_ms(16);
 break;

  case 4:
digitalWrite(5,HIGH);   // set the drain pump off
digitalWrite(6,LOW); // set the Solenoid Valve on
digitalWrite(2,LOW);  // set the PH down on
digitalWrite(3,LOW); // set the B nutrient solution on
digitalWrite(4,LOW); // set the A nutrient solution on
  CurrentTaskInterval = seconds_in_ms(10);
 break;


case 5:
digitalWrite(2,HIGH);  // set the PH down off
digitalWrite(6,LOW); // set the Solenoid Valve on
digitalWrite(3,LOW); // set the B nutrient solution on
digitalWrite(4,LOW); // set the A nutrient solution on
  CurrentTaskInterval = minutes_in_ms(6);
break;


case 6:
digitalWrite(3,HIGH); // set the B nutrient solution off
digitalWrite(6,LOW); // set the Solenoid Valve on
digitalWrite(4,LOW); // set the A nutrient solution on
    CurrentTaskInterval = minutes_in_ms(5.04);
break;


case 7:
digitalWrite(4,HIGH); // set the A nutrient solution off
digitalWrite(6,LOW); // set the Solenoid Valve on
    CurrentTaskInterval = minutes_in_ms(5);
break;


case 8:
digitalWrite(6,HIGH); // set the Solenoid Valve off
digitalWrite(7,LOW); // set the Nutrient Heater on
digitalWrite(8,HIGH); // set the Future Nutrient/PH contoller
{
  int phRaw;
  float phTmp, phOut, phMiliVolts;
 
  if(Serial.available() )
  {

  }
  phRaw = readADC(PHIN, 16666);    //Our averaged raw ADC value over ~ a single 60hz cycle
  phTmp = (5*(float)phRaw)/1023;   //Convert reading into a voltage based on a 5v reference
  phMiliVolts = phTmp * 1000;      //convert to milivolts
  phTmp = (2500-phMiliVolts)/5.25; //Since our circuit contains an initial gain, we must remove it here
  phOut = 7-(phTmp/59.16);            //ph is the numbers of "steps" from 7 (a step = mV/steps_per_mV)
  Serial.print("ADC1 Raw: ");
  Serial.println(phRaw);
  Serial.print("ADC1 Milivolts: ");
  Serial.println(phMiliVolts);
  Serial.print("pH: ");
  Serial.println(phOut);
  delay(1000); //1 sec
}
//pHduino avaerage routine, very effective for smoothing the readings
//alternatively you could perform software pass filtering here as well.
unsigned int readADC(int channel, unsigned reading_time)
{
  double d;
  int i;
  unsigned long t0_us;
  d = 0.0;
  i = 0;
  t0_us = micros();
  while((micros()-t0_us)<reading_time){
    i++;
    d += analogRead(channel);
  }
  d /= i;
  return (unsigned int)(d); 
}
CurrentTaskInterval = days_in_ms(1);
break;

case 9:
case 10:
case 11:
case 12:
case 13:
case 14:
case 15:
case 16:
case 17:
case 18:
case 19:
case 20:
case 21:
digitalWrite(6,LOW); // set the Solenoid Valve on/ top up
CurrentTaskInterval = seconds_in_ms(20);
digitalWrite(6,HIGH); // set the Solenoid Valve off/ top up
CurrentTaskInterval = days_in_ms(1);
break;

case 22:
// Start over again in one week from the START of the cycle
    LastTaskTime = CycleStartTime;
    CurrentTaskInterval = weeks_in_ms(1);
    Task = 0;   //starts loop
    break;
  }
}
37  Using Arduino / Programming Questions / Re: structure question on: February 20, 2012, 08:01:39 am
Well call it what you want, its like some thing that I have never seen b4, and I started programming as a kid with Fortran and Cobal
or was it Cobalt cant remember now. I didn't make much more then hello world stuff on a machine the size of your office, they gave me a whopping 1200k to play with. I'm still not clear why this is better, it looks to me it still follows a logical path A B C D and in my mind I'm just trying to multitask, there should be tricks to fake that. I loaded QM and the modeler program, seems you build things similar to visual basic graphically out the program, guess you can build it code level, but if you have a choice between a car or a bike Ill take the car. The code itself makes no sense I outputted an example of blinky led that's suppose to blink every 2 seconds nothing in the program pointed to to a 2 wouldn't compile either.
That brings us back to why are we wasting our time with C/Arduino when eventually you will be told you cant get there from here.

38  Using Arduino / Programming Questions / Re: structure question on: February 19, 2012, 03:44:40 pm
ok googled state machine found QP sounds complicated, going to have learn a whole new programing language.
looking forward to that lol.


39  Using Arduino / Programming Questions / structure question on: February 19, 2012, 02:23:37 pm
OK I have this code and now I'm running into a problem
If you look at for example case 4 it set my PH Solenoid  B and A on then I break for X seconds, that's going to be a variable, to turn the PH off.
Ok fine but my problem is its going to change Solenoid  B and A time on also. I want all of them all to be variables, with their own times
and run them together. I cant write it ABCD as being a variable who knows whats 1st.
Make any sense its a little hard to explain.

Code:
  case 4:
digitalWrite(5,HIGH);   // set the drain pump off
digitalWrite(6,LOW); // set the Solenoid Valve on
digitalWrite(2,LOW);  // set the PH down on
digitalWrite(3,LOW); // set the B nutrient solution on
digitalWrite(4,LOW); // set the A nutrient solution on
  CurrentTaskInterval = seconds_in_ms({3});
 break;


case 5:
digitalWrite(2,HIGH);  // set the PH down off
digitalWrite(6,LOW); // set the Solenoid Valve on
digitalWrite(3,LOW); // set the B nutrient solution on
digitalWrite(4,LOW); // set the A nutrient solution on
  CurrentTaskInterval = minutes_in_ms(6);
break;
40  Using Arduino / Programming Questions / Confusing question on: February 18, 2012, 08:49:39 am
I have a problem and its even hard to describe what it is.
My program runs case 1 2 3 ect for x amount of time it sounds simple, except the times are going to be variable.
Case 4 may not be case 4 anymore as you change up the time it might even become case1
The variables will be changed into the sketch via Visual basic I could probably fix it there.
Or is there a simple solution I don't see yet.


41  Using Arduino / Programming Questions / Re: help me with a cycle timer on: February 09, 2012, 12:00:42 pm
Thanks I guess this is right, it compiles havn't tried it yet.
look Pretty though.

Code:
   //  Some macros for defining time intervals in milliseconds
#define seconds_in_ms(s) ((s)*1000UL)
#define minutes_in_ms(m) ((m)*60UL*1000UL)
#define hours_in_ms(h)   ((h)*60UL*60UL*1000UL)
#define days_in_ms(d)    ((d)*24UL*60UL*60UL*1000UL)
#define weeks_in_ms(w)   ((w)*7UL*24UL*60UL*60UL*1000UL)

unsigned long CycleStartTime = 0;
unsigned long LastTaskTime = 0;
unsigned long CurrentTaskInterval = 0;
unsigned Task = 3;  //All you had to change was this. 1st time, Task will = 3.


void setup() {


   pinMode(2, OUTPUT);   //PH down
   pinMode(3, OUTPUT);  //B nutrient solution
   pinMode(4, OUTPUT);  //A nutrient solution
   pinMode(5, OUTPUT);  //Drain pump
   pinMode(6, OUTPUT);   //Solenoid Valve
   pinMode(7, OUTPUT);  //Nutrient Heater
   pinMode(8, OUTPUT);  //Not used Future Nutrient/PH contoller

  digitalWrite(2, HIGH);     //PH down off
  digitalWrite(3, HIGH);  //B nutrient solution off
  digitalWrite(4, HIGH);  //A nutrient solution off
  digitalWrite(5, HIGH);  //Drain pump off
  digitalWrite(6, HIGH);   //Solenoid Valve off
  digitalWrite(7, HIGH);  //Nutrient Heater off
}

void loop() {


  unsigned long currentTime = millis();

  // If the time has not yet come to perform a task
  if(currentTime - LastTaskTime >= CurrentTaskInterval)
  LastTaskTime = currentTime;

  switch (Task)
  {
  case 0:
    CycleStartTime = currentTime;  // Remember this time

   digitalWrite(5,LOW);   // set the drain pump on flush

    CurrentTaskInterval = minutes_in_ms(17);
    break;

  case 1:
    digitalWrite(5,HIGH);   // set the drain pump off flush
    digitalWrite(6,LOW); // set the Solenoid Valve on flush
    CurrentTaskInterval = hours_in_ms(1);
 break;

 case 2:
    digitalWrite(6,HIGH); // set the Solenoid Valve off flush
    digitalWrite(7,LOW); // set the Nutrient Heater on flush
    CurrentTaskInterval = minutes_in_ms(60);
 break;

 case 3:
    digitalWrite(5,LOW);   // set the drain pump on
      digitalWrite(7,HIGH); // set the Nutrient Heater off
    CurrentTaskInterval = minutes_in_ms(17);
 break;

  case 4:
    digitalWrite(5,HIGH);   // set the drain pump off
    digitalWrite(6,LOW); // set the Solenoid Valve on
    digitalWrite(2,LOW);  // set the PH down on
    digitalWrite(3,LOW); // set the B nutrient solution on
    digitalWrite(4,LOW); // set the A nutrient solution on
    CurrentTaskInterval = seconds_in_ms(10);
 break;


case 5:
    digitalWrite(2,HIGH);  // set the PH down off
    digitalWrite(6,LOW); // set the Solenoid Valve on
    digitalWrite(3,LOW); // set the B nutrient solution on
    digitalWrite(4,LOW); // set the A nutrient solution on
    CurrentTaskInterval = minutes_in_ms(6);

break;


case 6:
digitalWrite(3,HIGH); // set the B nutrient solution off
digitalWrite(6,LOW); // set the Solenoid Valve on
digitalWrite(4,LOW); // set the A nutrient solution on
    CurrentTaskInterval = minutes_in_ms(5.04);


break;

case 7:
digitalWrite(4,HIGH); // set the A nutrient solution off
digitalWrite(6,LOW); // set the Solenoid Valve on

    CurrentTaskInterval = minutes_in_ms(5);


break;


case 8:
digitalWrite(6,HIGH); // set the Solenoid Valve off
digitalWrite(7,LOW); // set the Nutrient Heater on
digitalWrite(8,HIGH); // set the Future Nutrient/PH contoller off

CurrentTaskInterval = days_in_ms(1);

break;

case 9:
case 10:
case 11:
case 12:
case 13:
case 14:
case 15:
case 16:
case 17:
case 18:
case 19:
case 20:
case 21:
digitalWrite(6,LOW); // set the Solenoid Valve on/ top up
CurrentTaskInterval = seconds_in_ms(20);
digitalWrite(6,HIGH); // set the Solenoid Valve off/ top up
CurrentTaskInterval = days_in_ms(1);
break;

case 22:
// Start over again in one week from the START of the cycle
    LastTaskTime = CycleStartTime;
    CurrentTaskInterval = weeks_in_ms(1);
    Task = 0;   //statrts loop at 0
    break;
  }
   }
42  Using Arduino / Programming Questions / Re: help me with a cycle timer on: February 09, 2012, 11:13:34 am
Dam, still playing with this thing grrrrr
Tried this it wont work, thought I had it grrr
The program starts with the digitalWrite(5,LOW);   // set the drain pump on
that's it stalls won't go further.

Code:
   //  Some macros for defining time intervals in milliseconds
#define seconds_in_ms(s) ((s)*1000UL)
#define minutes_in_ms(m) ((m)*60UL*1000UL)
#define hours_in_ms(h)   ((h)*60UL*60UL*1000UL)
#define days_in_ms(d)    ((d)*24UL*60UL*60UL*1000UL)
#define weeks_in_ms(w)   ((w)*7UL*24UL*60UL*60UL*1000UL)

unsigned long CycleStartTime = 0;
unsigned long LastTaskTime = 0;
unsigned long CurrentTaskInterval = 0;
unsigned Task = 3;  //All you had to change was this. 1st time, Task will = 3.


void setup() {


   pinMode(2, OUTPUT);   //PH down
   pinMode(3, OUTPUT);  //B nutrient solution
   pinMode(4, OUTPUT);  //A nutrient solution
   pinMode(5, OUTPUT);  //Drain pump
   pinMode(6, OUTPUT);   //Solenoid Valve
   pinMode(7, OUTPUT);  //Nutrient Heater
   pinMode(8, OUTPUT);  //Not used Future Nutrient/PH contoller

  digitalWrite(2, HIGH);     //PH down off
  digitalWrite(3, HIGH);  //B nutrient solution off
  digitalWrite(4, HIGH);  //A nutrient solution off
  digitalWrite(5, HIGH);  //Drain pump off
  digitalWrite(6, HIGH);   //Solenoid Valve off
  digitalWrite(7, HIGH);  //Nutrient Heater off
}

void loop() {


  unsigned long currentTime = millis();

  // If the time has not yet come to perform a task
  if (currentTime - LastTaskTime < CurrentTaskInterval)
    return;   // Nothing to do

  LastTaskTime = currentTime;

  switch (Task)
  {
  case 0:
    CycleStartTime = currentTime;  // Remember this time

   digitalWrite(5,LOW);   // set the drain pump on flush

    CurrentTaskInterval = minutes_in_ms(17);
    break;

  case 1:
    digitalWrite(5,HIGH);   // set the drain pump off flush
    digitalWrite(6,LOW); // set the Solenoid Valve on flush
    CurrentTaskInterval = hours_in_ms(1);
 break;

 case 2:
    digitalWrite(6,HIGH); // set the Solenoid Valve off flush
    digitalWrite(7,LOW); // set the Nutrient Heater on flush
    CurrentTaskInterval = minutes_in_ms(60);
 break;

 case 3:
    digitalWrite(5,LOW);   // set the drain pump on
      digitalWrite(7,HIGH); // set the Nutrient Heater off
    CurrentTaskInterval = minutes_in_ms(17);
 break;

  case 4:
    digitalWrite(5,HIGH);   // set the drain pump off
    digitalWrite(6,LOW); // set the Solenoid Valve on
    digitalWrite(2,LOW);  // set the PH down on
    digitalWrite(3,LOW); // set the B nutrient solution on
    digitalWrite(4,LOW); // set the A nutrient solution on
    CurrentTaskInterval = seconds_in_ms(10);
 break;


case 5:
    digitalWrite(2,HIGH);  // set the PH down off
    digitalWrite(6,LOW); // set the Solenoid Valve on
    digitalWrite(3,LOW); // set the B nutrient solution on
    digitalWrite(4,LOW); // set the A nutrient solution on
    CurrentTaskInterval = minutes_in_ms(6);

break;


case 6:
digitalWrite(3,HIGH); // set the B nutrient solution off
digitalWrite(6,LOW); // set the Solenoid Valve on
digitalWrite(4,LOW); // set the A nutrient solution on
    CurrentTaskInterval = minutes_in_ms(5.04);


break;

case 7:
digitalWrite(4,HIGH); // set the A nutrient solution off
digitalWrite(6,LOW); // set the Solenoid Valve on

    CurrentTaskInterval = minutes_in_ms(5);


break;


case 8:
digitalWrite(6,HIGH); // set the Solenoid Valve off
digitalWrite(7,LOW); // set the Nutrient Heater on
digitalWrite(8,HIGH); // set the Future Nutrient/PH contoller off

CurrentTaskInterval = days_in_ms(1);

break;

case 9:
case 10:
case 11:
case 12:
case 13:
case 14:
case 15:
case 16:
case 17:
case 18:
case 19:
case 20:
case 21:
digitalWrite(6,LOW); // set the Solenoid Valve on/ top up
delay (20000);
digitalWrite(6,HIGH); // set the Solenoid Valve off/ top up
CurrentTaskInterval = days_in_ms(1);
break;

case 22:
// Start over again in one week from the START of the cycle
    LastTaskTime = CycleStartTime;
    CurrentTaskInterval = weeks_in_ms(1);
    Task = 0;   //statrts loop at 0
    break;
  }
}
43  Development / Suggestions for the Arduino Project / Thinking ouside the box on: February 04, 2012, 08:13:03 am
5 Things I you might like to to see in the future.

1) stack-duino, why no stack 2 or 4 of them up on one another/but that would involve a peave of mine, a power pin that's not there.
2) Higher level programing, the bottom line does it work, I have seen some really bad code that works really well and that's what counts.
Don't give me your mumbo jumbo about clock speed, If that's the most important thing for you, you be writing in machine language not C
3) As the prices come down maybe integrate some WIFI, and multi-core processing.
4) Plugs....those pins suck long term they fall out.
5) Can some one write a good programing manual that's complete, we got them out there missing tons of info.
44  Using Arduino / Programming Questions / Re: help me with a loop on: February 03, 2012, 11:32:55 pm
ok that makes sense, Task = 0; at the bottom sends it back to case 0 although I'm thinking it should be moved to the end.
unsigned Task = 3; starts it at case 3, but why did you declare one unsighned and the other one not ?.
45  Using Arduino / Programming Questions / Re: help me with a loop on: February 03, 2012, 09:18:02 pm
"unsigned Task = 3;  // <<=============== All you had to change was this. 1st time, Task will = 3."
Ok sounds simple enough, but how does that work? I'm just try to rap my head around this.
unsigned means no negative numbers and task = 3 as far as I understand
tnks
Pages: 1 2 [3] 4 5 ... 8