Pages: [1]   Go Down
Author Topic: Virtual latching relay  (Read 615 times)
0 Members and 1 Guest are viewing this topic.
Glassport,Pa@ USA
Offline Offline
Full Member
***
Karma: 0
Posts: 150
shoop teh whoop!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:

//z-parakeet inc.'s Fire Alarm Sketch
#include <LiquidCrystal.h>
// LiquidCrystal display with:
// rs on pin 12
// rw on pin 11
// enable on pin 10
// d4, d5, d6, d7 on pins 5, 4, 3, 2
LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);

int ledPin = 13; // choose the pin for the LED
int buzzerPin = 9; //buzzer/alertor
int inputPin = 8;               // choose the input pin (for a pushbutton)
int val = 0;            // variable for reading the pin status
int truPin = 7;
int Alarms = 6;
int sil = 0;
void setup() {

 pinMode(buzzerPin, OUTPUT);   //declare BUZZER or allertor as a output!
 pinMode(ledPin, OUTPUT);      // declare LED as output
 pinMode(inputPin, INPUT);  // declare pushbutton as input
 pinMode(truPin, OUTPUT);
 pinMode(Alarms, OUTPUT);
     digitalWrite(buzzerPin, HIGH);
     digitalWrite(ledPin, HIGH);
     digitalWrite(truPin, HIGH);
       lcd.print("System Loading");
       lcd.print(".");
       delay(1000);
       lcd.print("..");
               delay(1000);
       lcd.print("...");
   delay(1000);
     lcd.print("System Stats: Standby");
   digitalWrite(buzzerPin, LOW);
   digitalWrite(ledPin, LOW);
   digitalWrite(truPin, LOW);
delay(2000);
}


 

void loop(){
 val = digitalRead(inputPin);  // read input value
 delay(0); //used to be a delay, but changed cuz of my update!
 if (val == HIGH) {      // check if the input is HIGH
 lcd.print("ALERT! TROUBLE OR FIRE");
   digitalWrite(truPin, HIGH);
   digitalWrite(ledPin, HIGH);  // turn LED ON
   delay(50);
   digitalWrite(ledPin, LOW);
   delay(50);
   digitalWrite(buzzerPin, HIGH);
     lcd.print("CHECK PULL STATIONS");
   delay(50);
   lcd.print("OR TEST SWITCH");
   digitalWrite(buzzerPin, LOW);
   delay(50);
   digitalWrite(Alarms, HIGH);
 } else {
     lcd.print("Standby.");
   digitalWrite(ledPin, LOW); // turn LED OFF
   digitalWrite(truPin, LOW);
   digitalWrite(Alarms, LOW);
  
 }
}




ive been posting that alot, but i need to know how to have it once the button is activated, it wont stop till i press the reset button on the arduino duemilinove.
Logged

[ch9618][ch9618][ch9618][ch9618][ch9618][ch9618][ch9618][ch9618][ch9618][ch9618][ch9618][ch9618][ch9618][ch9618][ch9618][ch9618][ch9618]

London
Offline Offline
Tesla Member
***
Karma: 10
Posts: 6250
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Is your button connected using a resistor? The tutorial here explains about pull-up and pull down resistors: http://www.arduino.cc/en/Tutorial/Button

You can also use internal pull-up resistors; this tutorial explains more about digital pins and how to enable the internal pull-up resistors: http://www.arduino.cc/en/Tutorial/DigitalPins
« Last Edit: March 30, 2009, 12:00:18 pm by mem » Logged

SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 124
Posts: 6637
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What you're looking for it called a "state machine"  in technical circles.  Basically, the actions you perform and the inputs you watch are dependent on some "state" variable that you save:  "If the relay is off, look for the ON button.  If the relay is ON, look for the off button.
Code:
#define RELAY_ON 1
#define RELAY_OFF 0

byte state = RELAY_OFF;

void loop()
{
 if (state == RELAY_OFF) {
   if (digitalRead(inputPin)) {
     alarm_on();
     state = RELAY_ON;
   }
 } else if (state == RELAY_ON) {
   if (digitialRead(resetPin)) {
     alarm_off();
     state = RELAY_OFF;
    }
  }
}
As you get more states, you have a good excuse to learn about the "case" statement.
Logged

Glassport,Pa@ USA
Offline Offline
Full Member
***
Karma: 0
Posts: 150
shoop teh whoop!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

huh >smiley-grin

i am still kinda new to arduino, but i dont understand...
Logged

[ch9618][ch9618][ch9618][ch9618][ch9618][ch9618][ch9618][ch9618][ch9618][ch9618][ch9618][ch9618][ch9618][ch9618][ch9618][ch9618][ch9618]

Connecticut, US
Offline Offline
Edison Member
*
Karma: 2
Posts: 1036
Whatduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


Change:

Quote
void loop(){
 val = digitalRead(inputPin);  // read input value

To:

Quote
void loop(){
  [glow]if (!val)[/glow]
      val = digitalRead(inputPin);  // read input value


westfw:  he said the reset button on the board.  His state machine is a one-way gate from "off until input" to "on forever."  Not what I would do, but...
Logged

Pages: [1]   Go Up
Jump to: