Show Posts
Pages: 1 [2] 3 4
16  Using Arduino / Programming Questions / Re: Delay without delay help on: January 26, 2013, 11:54:48 pm
The reason you have to hold the button, is because you don't have a Latch. Look at the state change detection code (I can't think of the actual name right now) it's in your example codes. Just implement that into this code and you will be good to go.

The button will still work in the way I want it to with this feature? 

Also, do you think this will help fix my problem with it only working one time?

Thank you.
17  Using Arduino / Programming Questions / Re: Delay without delay help on: January 25, 2013, 06:23:35 pm
snippets-r-us.com is down the internet a ways. You are more likely to get help with snippets there. Here, we expect to see ALL of your code.

Ask and you shall receive

Code:
#include <DAC6573.h>
#include <SoftwareSerial.h>
#include <PCF8574.h>
#include <Wire.h>
#include <CONVECTRON.h>
#include <LiquidCrystal_I2C.h>
#include <Relay.h>
#include <Button.h>
#include <Bounce.h>


CONVECTRON sensor(A0);
Button button1(5);
Button button2(6);
Button button3(7);
Relay contactor1(2, true);
Relay contactor2(3, true);
Relay contactor3(4, true);
#define BUTTON 13
#define RTS 8
#define CTS 9
LiquidCrystal_I2C lcd(0b0111000,20,4);
PCF8574 xport(0b0111111);
SoftwareSerial IGC(10, 11);
DAC6573 myDAC6573(DAC6573_DEFAULT_ADDRESS);
const unsigned long oneinterval=3000;
const unsigned long twointeveral=6000;

unsigned long onetimer;
unsigned long twotimer;

// Instantiate a Bounce object with a 5 millisecond debounce time
Bounce bouncer = Bounce( BUTTON,5 );

void setup() {
  Serial.begin(9600);
  pinMode(RTS, INPUT);
  pinMode(CTS, OUTPUT);
  Wire.begin();
  button1.begin();
  button2.begin();
  button3.begin();
  contactor1.begin();
  contactor2.begin();
  contactor3.begin();
  pinMode(BUTTON,INPUT);
  IGC.begin(9600);
  onetimer = millis();
  twotimer = millis();
}

void loop() {
 
  myDAC6573.DAC6573_SetChannel(sensor.DAC() , 0);
 
 
 
  if (IGC.available()) {Serial.write(IGC.read());}
  if (Serial.available() && digitalRead(RTS) == LOW)
  {
    digitalWrite(CTS, HIGH);
    IGC.write(Serial.read());
    digitalWrite(CTS, LOW);
  }
 
  lcd.init();
  lcd.backlight();
   char buffer[10];
dtostre(sensor.readpressure(), buffer, 1, 0x04);
  lcd.setCursor(0,0);
  lcd.print("Funnel");
  lcd.setCursor(7,0);
  lcd.print(buffer);
  lcd.setCursor(15,0);
  lcd.print("Torr");
 
 // Update the debouncer
  bouncer.update ( );
 
 // Get the update value
 int value = bouncer.read();
 if ( value == HIGH) {
   if (button1.read() == LOW && button2.read() == LOW && button3.read() == LOW) {
   xport.PCF8574_SetPin(0, 1);
   contactor1.off();
   xport.PCF8574_SetPin(1, 1);
   xport.PCF8574_SetPin(2, 1);
   contactor2.off();
   contactor3.off();
   }
  else if (button1.read() == HIGH && button2.read() == LOW && button3.read() == LOW) {
   xport.PCF8574_SetPin(0, 0);
   contactor1.on();
   xport.PCF8574_SetPin(1, 1);
   xport.PCF8574_SetPin(2, 1);
   contactor2.off();
   contactor3.off();
 }

  else if (button2.read() == HIGH && button3.read() == LOW && button1.read() == LOW){
     xport.PCF8574_SetPin(1, 0);
     contactor2.on();
     xport.PCF8574_SetPin(0, 1);
     xport.PCF8574_SetPin(2, 1);
     contactor1.off();
     contactor3.off();
   }
 
  else if (button3.read() == HIGH && button1.read() == LOW && button2.read() == LOW){
     xport.PCF8574_SetPin(2, 0);
     contactor3.on();
     xport.PCF8574_SetPin(1, 1);
     xport.PCF8574_SetPin(0, 1);
     contactor2.off();
     contactor1.off();
   }
 
 else  if (button1.read() == HIGH && button2.read() == HIGH && button3.read() == LOW){
     xport.PCF8574_SetPin(0, 0);
     xport.PCF8574_SetPin(1, 0);
     contactor1.on();
     xport.PCF8574_SetPin(2, 1);
     contactor3.off();
     if ((millis() - onetimer) >= oneinterval){
      contactor2.on();
      onetimer = millis();
     }
  }
   
  else if (button1.read() == HIGH && button2.read() == HIGH && button3.read() == HIGH){
    xport.PCF8574_SetPin(0, 0);
    xport.PCF8574_SetPin(1, 0);
    xport.PCF8574_SetPin(2, 0);
    contactor1.on();
   delay(3000);
   contactor2.on();
  delay(3000);
    contactor3.on();
 }
 }
 else {
 }
 }
18  Using Arduino / Programming Questions / Re: Delay without delay help on: January 25, 2013, 05:56:52 pm
You need some sort of state machine, or keeping track of elapsed time. Try reading this:

http://www.gammon.com.au/blink


I have tried that liked this
Code:
else  if (button1.read() == HIGH && button2.read() == HIGH && button3.read() == LOW){
     xport.PCF8574_SetPin(0, 0);
     xport.PCF8574_SetPin(1, 0);
     contactor1.on();
     xport.PCF8574_SetPin(2, 1);
     contactor3.off();
     if ((millis() - onetimer) >= oneinterval){
      contactor2.on();
      onetimer = millis();
     }
  }

However, it only works one time and I have to hold the button down.  The idea of the button is to be a set button that wouldn't have to be held down to get everything on. 
19  Using Arduino / Programming Questions / Delay without delay help on: January 25, 2013, 05:32:57 pm
Hey guys.  I have a pretty long sketch for a project I am working on.  Currently it reads the status of one button and then when that button goes high it reads the status of three other switches to see what it needs to do.  For example if switch 1 and 2 are high and the button is pushed it would turn on things for 1 and 2.  Everything works, however, I have a delay built into it and I want to eliminate with Millis();  I have tried several things with it and haven't gotten it to work.  It would work once, but I would have to hold down the button until my "interval" had passed.  Here is part of my sketch

Code:
bouncer.update ( );
 
 // Get the update value
 int value = bouncer.read();
 if ( value == HIGH) {
else  if (button1.read() == HIGH && button2.read() == HIGH && button3.read() == LOW){
     xport.PCF8574_SetPin(0, 0);
     xport.PCF8574_SetPin(1, 0);
     contactor1.on();
     xport.PCF8574_SetPin(2, 1);
     contactor3.off();
     delay(3000);
      contactor2.on();
  }
   }
else {
}
}

Thanks for any input!
20  Using Arduino / Networking, Protocols, and Devices / Re: I2C interface with DAC6573- RESOLVED on: January 22, 2013, 12:25:49 pm
loose connections, happens all around the world smiley-wink

No, because it doesn't work with that address. It finds it, but doesn't communicate properly.
21  Using Arduino / Networking, Protocols, and Devices / Re: I2C interface with DAC6573- RESOLVED on: January 21, 2013, 07:19:04 pm
one question remains, could you test:

If you GND both address lines and you use the I2C scanner of nick Gammon, does it find the device?
similar for other address pin combinations (high/low)?

- http://www.gammon.com.au/forum/?id=10896 - search for scanner (~@ 80% of the page)


Thank you for the source.  Yes it does find it with all of them low and the same address, so I do not know why it didn't work with all of them low. 
22  Using Arduino / Networking, Protocols, and Devices / Re: I2C interface with DAC6573- RESOLVED on: January 21, 2013, 03:30:09 pm
I got it working by changing the A0 pin to 5V and then changing the address.

Thanks guys.
23  Using Arduino / Networking, Protocols, and Devices / Re: I2C interface with DAC6573 on: January 21, 2013, 02:16:51 pm
Lets try another "stupid "question smiley-wink

How are the address lines of the chip connected?
Are they GND?

If "stupid" questions get me to a solution, it is no problem smiley-wink

Yes, they are all connected to GND.
24  Using Arduino / Networking, Protocols, and Devices / Re: I2C interface with DAC6573 on: January 21, 2013, 01:51:26 pm
Sorry, stupid slip of the mind  smiley-red


No problem.
25  Using Arduino / Networking, Protocols, and Devices / Re: I2C interface with DAC6573 on: January 21, 2013, 01:51:11 pm
If you include header files in the library header file, it is not necessary to include them in the library source file, too.

That wouldn't create a problem though, right?
26  Using Arduino / Networking, Protocols, and Devices / Re: I2C interface with DAC6573 on: January 20, 2013, 07:04:03 pm
Where do you read the value of the DAC?
Which statement does that?


I set the value.
27  Using Arduino / Networking, Protocols, and Devices / I2C interface with DAC6573- RESOLVED on: January 19, 2013, 01:21:13 am
Hi guys,

I am trying to communicate with a DAC6574 but I get the same I2C sequence no matter how I change the code. It looks like the attached image.



Do you need the code for it?  This is the Arduino sketch
Code:
#include <Wire.h>
#include <DAC6573.h>
 
DAC6573 myDAC6573(DAC6573_DEFAULT_ADDRESS);

void setup() {
    Wire.begin(); //Start the I2C bus
    Serial.begin (9600);
}
 
void loop()
{
  byte channel=1;
  static word DAC;
  static int delta=10;
  Serial.print("DAC");
  Serial.println(DAC);
  delay(100);
  
  myDAC6573.DAC6573_SetChannel(DAC,channel);
  DAC=DAC+delta;
  if (DAC > 1020) {delta = -10;}
  if (DAC < 20) {delta = 10;}
  
}
  

I will post library too if it is needed.
28  Using Arduino / Programming Questions / Re: Constructor parameter issues on: January 15, 2013, 05:04:25 pm
What are you setting theObject.pin to?  You need to assign it in the constructor:
Code:
this->pin = pin;
... and the same with "kind".  You're just throwing away those passed parameters.

Of course, thank you.  I got that working again.  But it still seems to be ignoring my "kind" parameter and treating the pin the same regardless. 
That was addressed in an earlier reply:

Code:
if (kind=true) {
is wrong - it should be == not =.

The comparison vs. assignment one?  I didn't understand that, but now it is working.  Thank you again for your help.
29  Using Arduino / Programming Questions / Re: Constructor parameter issues on: January 15, 2013, 04:56:49 pm
What are you setting theObject.pin to?  You need to assign it in the constructor:
Code:
this->pin = pin;
... and the same with "kind".  You're just throwing away those passed parameters.

Of course, thank you.  I got that working again.  But it still seems to be ignoring my "kind" parameter and treating the pin the same regardless. 
30  Using Arduino / Programming Questions / Re: Constructor parameter issues on: January 15, 2013, 04:46:10 pm
This is what I have changed it to and now it doesn't work at all.
.h
Code:

class Relay
{
  public:
    Relay(int pin, bool kind); //kind 1 is positive on kind 2 is negative on
    void begin();
    void on();
    void off();
    int pin;
    bool kind;
  private:
   
};
.cpp
Code:
Relay::Relay(int pin, bool kind)
{
}

void Relay::begin(){
pinMode(pin, OUTPUT);
}

void Relay::on(){
if (kind=true){
digitalWrite(pin, HIGH);
}
else if (kind=false) {
  digitalWrite(pin, LOW);
  }

}

void Relay::off(){
if (kind=true) {
  digitalWrite(pin, LOW);
  }
else if (kind=false){
digitalWrite(pin, HIGH);
}

}

Pages: 1 [2] 3 4