Show Posts
Pages: [1]
1  Using Arduino / Programming Questions / Re: Timing Issues on: February 13, 2013, 08:06:16 pm
One other thing I failed to mention, Day 1 should stay the same for 24 hours and should point to the second position in the array. As soon as it puts out a negative number (at the 3rd hour) it also starts to point to a different position in the Fan array. As you can tell I am new to this so I apologize if the answer is completely obvious.
2  Using Arduino / Programming Questions / Re: Timing Issues on: February 13, 2013, 07:45:56 pm
Thank you for merging the w posts. It will not happen again.
3  Using Arduino / Programming Questions / Re: Timing issues on: February 13, 2013, 07:32:39 pm
Code:

int DayCount;
float relayMillis;
float Hour,Minute,Second,ms;
float Day;
unsigned long start, finished, elapsed;

int FanTimeArray[9] = {
  0,24, 23, 22, 21, 20,19,18,24}; // In Hours

void setup() {

  pinMode(12,OUTPUT);

  Serial.begin(9600);

}


void loop() {

  intiatClock();
  FanRelay();

}


void intiatClock()
{

  unsigned long over;
  start=millis();
  elapsed=finished-start;
  Hour=1+int(start/3600000);
  over=start%3600000;
  Minute=1+int(over/60000);
  over=over%60000;
  Second=int(over/1000);
  ms=over%1000;
  Day=1+int(start/86400000);
}




void FanRelay(){

  long relayTriggerInterval;
  long relayTriggerInterval_after8;
  int intDay;
 
  intDay=Day; //Change to int
 
  relayTriggerInterval=86400000/FanTimeArray[intDay];


    if(intDay<8){
      if(millis() - relayMillis > relayTriggerInterval){
        relayMillis = millis();
      }
     else{
       //Do nothing
     }
   
    }
}


















4  Using Arduino / Programming Questions / Timing issues on: February 13, 2013, 07:20:10 pm
I am trying to have a fan trigger at an value stored in a array. After the 3rd hour starts  it begins to give me a negative number. Any ideas?

Code:
int FanTimeArray[9] = {
  24,24, 23, 22, 21, 20,19,18,24};

void FanRelay(){

  relayTriggerInterval=86400000/FanTimeArray[Day];
 
    if(Day<8){    
      if(millis() - relayMillis > relayTriggerInterval){
      relayMillis=millis();
      }
}


5  Using Arduino / Programming Questions / Timing Issues on: February 13, 2013, 07:06:57 pm
I am trying to have a fan trigger at an value stored in a array. After the 3rd hour and starts to through a negative number. Any ideas?

Code:
int FanTimeArray[9] = {
  24,24, 23, 22, 21, 20,19,18,24};

void FanRelay(){

  relayTriggerInterval=86400000/FanTimeArray[Day];
 
    if(Day<8){     
      if(millis() - relayMillis > relayTriggerInterval){
      relayMillis=millis();
      }
}


6  Using Arduino / Programming Questions / Re: Unresponsive Button Presses on: February 10, 2013, 10:03:05 am
I am completely new to this and I am sure there are many mistakes made in this chicken scratch of a sketch. I am assuming through by comment that there are definitely simpler ways of doing this.
7  Using Arduino / Programming Questions / Re: Unresponsive Button Presses on: February 10, 2013, 09:38:48 am
Now that i am looking at it I agree with you PaulS. But in regards to the rest of the post I am not using any delays im using millis().
8  Using Arduino / Programming Questions / Re: Unresponsive Button Presses on: February 09, 2013, 07:46:48 pm
Code:

#include "SoftwareSerial.h"
#include "DHT.h"


#define DHTPIN 5     // what pin we're connected to
#define DHTTYPE DHT22   // DHT 22  (AM2302)
DHT dht(DHTPIN, DHTTYPE);

//Variable
int buttonStateSet = 0;
int buttonStateUp = 0;
int buttonStateDown = 0;

int buttonSetPin   = 12;
int buttonUpPin    = 10;
int buttonDownPin  = 11;
int lastButtonState = 0;
int lastButtonStateUp=0;
int lastButtonStateDown=0;

int relayPin = 4;

int buttonStateSetCount;
int buttonStateHourCount;
int buttonStateHumCount;
int setVariableZero = 0;
const int TxPin = 9;
int displayCount = 0;
SoftwareSerial mySerial = SoftwareSerial(255, TxPin);
float lastTempChange  =0;
float lastHumChane  =0;
long lastTimeStamped;
long lastTimeStamped_2;
void setup() {
 
  dht.begin();
 
  pinMode(TxPin, OUTPUT);
  digitalWrite(TxPin, HIGH);
 
  pinMode(buttonSetPin,INPUT);
  pinMode(buttonUpPin,INPUT);
  pinMode(buttonDownPin,INPUT);
  pinMode(relayPin,OUTPUT);
 
  mySerial.begin(9600); 
 
 
  delay(100);
  mySerial.write(12);                 // Clear             
  mySerial.write(17);                 // Turn backlight on
  delay(5);                           // Required delay
  mySerial.print("== Jar Test ==");          // First line
  mySerial.write(13);                 // Form feed
  mySerial.print("1.01v");             // Second line
  mySerial.write(212);                // Quarter note
  mySerial.write(220);                // A tone
 
  delay(3000);
  mySerial.write(12);
  display_Stat();
 
}

void loop() {
 
  unsigned long currentMillis = millis();
 
 //if( digitalRead(12)==HIGH){
 buttonSetCall();
// }
 //if(digitalRead(10) == HIGH){
 buttonUpCall();
 //}
// if(digitalRead(11)==HIGH){
 buttonDownCall();
 //}
 
 
  if(buttonStateSetCount==0){
    if(currentMillis - lastTimeStamped > 5000){
      lastTimeStamped = currentMillis; 
      if(get_Humidity()!=lastHumChane)
      {
        display_Stat();
      }
      lastHumChane=get_Humidity();
       if(get_Temp()!= lastTempChange)
      {
        display_Stat();
      }
      lastTempChange=get_Temp();
    }
  }
// buttonStateUp   = digitalRead(buttonUpPin);
// buttonStateDown = digitalRead(buttonDownPin);
if(buttonStateSetCount==0){
    if(currentMillis - lastTimeStamped_2 > 5000){
if(get_Humidity()>=buttonStateHumCount){
  digitalWrite(relayPin,HIGH);
}
if(get_Humidity()<=buttonStateHumCount){
  digitalWrite(relayPin,LOW);
}
    }
}

}

float get_Humidity(){
   float h = dht.readHumidity();
   return h;
}
float get_Temp(){
  float t = dht.readTemperature();
  return t;
}
void buttonSetCall(){
 
  buttonStateSet  = digitalRead(buttonSetPin);
  if(buttonStateSet!=lastButtonState){
    if(buttonStateSet==HIGH){
       buttonStateSetCount++;
      // mySerial.write(12);
      // delay(5);
       //mySerial.write(12);
      // mySerial.print(buttonStateSetCount);
        if(buttonStateSetCount>=3){
            buttonStateSetCount=setVariableZero;
          //  mySerial.write(12);
           // delay(5);
          //  mySerial.print(buttonStateSetCount);
         }
        if(buttonStateSetCount==0){
            display_Stat();
        }
        if(buttonStateSetCount==1){
          display_Day();
        }
        if(buttonStateSetCount==2){
          display_Hum();
        }
    }
 
  }
  lastButtonState=buttonStateSet;
}

void buttonUpCall(){
  buttonStateUp  = digitalRead(buttonUpPin);
    if(buttonStateSetCount==1){
   
    if(buttonStateUp!=lastButtonStateUp){
     
      if(buttonStateUp==HIGH){
         buttonStateHourCount++;
         
          if(buttonStateHourCount>=25){
              buttonStateHourCount=setVariableZero;
           }
           display_Day();
        }
    }
    }
     
   
    if(buttonStateSetCount==2){
   
    if(buttonStateUp!=lastButtonStateUp){
     
      if(buttonStateUp==HIGH){
         buttonStateHumCount++;
         
          if(buttonStateHumCount>=101){
              buttonStateHumCount=setVariableZero;
           }
           display_Hum();
        }
      }
   
    }
    lastButtonStateUp=buttonStateUp;
}
void buttonDownCall(){
    buttonStateDown  = digitalRead(buttonDownPin);
    if(buttonStateSetCount==1){
   
    if(buttonStateDown!=lastButtonStateDown){
     
      if(buttonStateDown==HIGH){
          if(buttonStateHourCount>=1){
          buttonStateHourCount--;
      }
         
          if(buttonStateHourCount==0){
              buttonStateHourCount=24;
           }
           
             
 
           display_Day();
        }
    }
    }
     
   
    if(buttonStateSetCount==2){
   
    if(buttonStateDown!=lastButtonStateDown){
     
      if(buttonStateDown==HIGH){
              if(buttonStateHumCount>=0){
          buttonStateHourCount--;
      }
          if(buttonStateHumCount==0){
              buttonStateHumCount=100;
           }
           
           display_Hum();
        }
      }
   
    }
    lastButtonStateDown=buttonStateDown;

}





void display_Stat(){
 
  mySerial.write(12);                 // Clear   
  delay(5);   
  mySerial.print("Hum:");          // First line
  mySerial.print(get_Humidity());
  mySerial.print("%");
  mySerial.write(13);                 // Form feed
  mySerial.print("Temp:");             // Second line
  mySerial.print(get_Temp());
  mySerial.print("C");
  mySerial.write(212);


}
void display_Day(){
  delay(5);
  mySerial.write(12);                 // Clear             
  mySerial.print("Vents per day");          // First line
  mySerial.write(13);                 // Form feed
  mySerial.print("Set to:");             // Second linebuttonStateUpCount
  mySerial.print(buttonStateHourCount);
  mySerial.write(212);

}
void display_Hum(){
  delay(5);
  mySerial.write(12);                 // Clear             
  mySerial.print("Max humidity");          // First line
  mySerial.write(13);                 // Form feed
  mySerial.print("Set to:");             // Second line
  mySerial.print(buttonStateHumCount);
  mySerial.print("%");
  mySerial.write(212);

}







9  Using Arduino / Programming Questions / Unresponsive Button Presses on: February 09, 2013, 07:22:53 pm
I have written code that you can toggle through a few pages that display on a parallax lcd screen through button presses. The issue i am having is when I add code to read a humidity sensor in the "void loop()" my button presses become slow. Any ideas?
10  Using Arduino / Programming Questions / Re: Button change on: February 06, 2013, 08:18:09 pm
Works with the exception mills()
11  Using Arduino / Programming Questions / Button change on: February 06, 2013, 07:47:27 pm
I am trying to track a momentary button change. Press once and it goes to on mode (1), press again and goes to off mode (0). If button is in on mode and no action has been taken (pressing momentary button to go back to off mode) it will default back to zero after a desired time (3 sec). I am new to writing code and I know this is basic stuff but I am having a hard time. Any Ideas?
Pages: [1]