A little help with a piece of my sketch

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

A little help with a piece of my sketch

Postby bioreefdude » Fri May 25, 2012 10:39 pm

im trying to add a command to arduino but im not quite sure how to word the code.Here is what i got
Code: Select all
void runAto()
{ if(digitalRead(ato_input)== LOW){
      digitalWrite(ato,HIGH);
      lcd.setCursor(4,1);
      lcd.print("*");
    //digitalWrite(alarm, HIGH);
   
    }
    else {
    //digitalWrite(alarm, LOW);
     digitalWrite(ato, LOW);
     lcd.setCursor(4,1);
     lcd.print(" ");
    }
    delay (50);
i want the ato to remain high for 5 seconds as a fail safe if ato input switch gets stuck in on position . this is a water level float switch .when it comes on its usally just for a couple of seconds or just enough water to return to level. but i want the max time for it to be able to run only 5 seconds and never above but i dont want it to always run for 5 seconds either i want it to return the water to level as normal .any help would be appreciated
bioreefdude
 
Posts: 15
Joined: Thu Apr 12, 2012 8:01 pm

Re: A little help with a piece of my sketch

Postby adafruit_support_bill » Sat May 26, 2012 4:58 am

I think what you are saying is that you want the ATO to run for no more than 5 seconds at a time. This should not be difficult. using the "millis()" function to get the time-stamp of when you turned it on.

What is not clear is what you want to do next. If you wait for the float-switch to go off before starting the next top-off cycle, it is possible you may not ever fully top-off - even if your float switch is operational.

Also be aware that the millis counter will overflow approximately every 49 days. If the millis overflow coincides with an ATO cycle, you could overflow more than the millis counter if you do not check for it in your math. Another option is to use a RTC clock for your timing.
User avatar
adafruit_support_bill
 
Posts: 16072
Joined: Sat Feb 07, 2009 9:11 am


Return to Arduino

Who is online

Users browsing this forum: Google [Bot], mibignistinly and 11 guests

Stuff to buy from the Adafruit store and links to product documentation!


New Products [108]

Raspberry Pi[80]
 
FLORA[23]
 
Bunnie Studios[9]
 
FPGA[1]
 
mbed[11]
Arduino[60]
 
NETduino[14]
 
BeagleBone[24]
 
Android[6]
 
XBee[10]
More Dev Boards[31]


 
BoArduino[8]
 
SpokePOV[4]
 
TV-B-Gone[4]
 
MiniPOV[3]
 
SIM reader[3]
 
Microtouch[5]
 
Clocks & Watches[18]
 
Drawdio[4]
 
Brain Machine[1]
 
Game of Life[2]
 
MintyBoost[2]
More DIY Kits[16]


 
MaKey MaKey[3]
 
Tweet-a-Watt[5]
 
Young Engineers[33]
 
Discover Electronics[2]
 
Snap Circuits[4]
 
littleBits[3]
 
Project packs[8]


 
Breakout Boards[34]
LCDs & Displays[48]
Components & Parts[70]
Batteries & Power[49]
EL Wire/Tape/Panel[52]
LEDs[111]
 
Wireless[14]
Cables[62]
 
Lasers[6]
Sensors/Parts[145]
 
Enclosures/Cases[11]
 
Solar[11]
 
RFID / NFC[13]
Prototyping[70]
 
iDevices[13]
Tools[71]
 
Wearables[39]
 
CNC[37]
 
Robotics[29]
 
3D printing[1]
 
Materials[24]


 
Stickers[41]
 
Skill badges[55]
 
Books[25]
 
Circuit Playground[7]
 
Gift Certificates[4]