Show Posts
Pages: 1 2 [3] 4 5 6
31  Using Arduino / Programming Questions / Re: Blinking without delay on: May 08, 2011, 02:39:49 pm
Here is what I have so far.  "interval" integer from 1 to 12. If the time is right it needs to bring a certain pin high for a give amount of time. I am taking a snapshot of millis() giving it a number, adding it to the interval and comparing it to the current millis. It's not working. Any suggestions? Thanks!


Code:
if(((now.hour() == Breakfast) && (now.minute() == 0) && (now.second() == 0)) || ((now.hour() == Dinner) && (now.minute() == 0)  && (now.second() == 0))) { 
   
   unsigned long AutoMillis = millis();
 
   while(AutoMillis + (interval * OzMenu) < millis ) {
     if(automatic == true){ // Need t o add feedback
     digitalWrite(motorpin, HIGH);
     }
   }
     previousMillis = currentMillis;   
  //Feed the dog by rotating motor
 }


 
32  Using Arduino / Programming Questions / Blinking without delay on: May 08, 2011, 11:41:57 am
Hello all,

I am having  trouble with a timer. I need to energize a Mosfet for a time period (Interval * 1000) milliseconds. I have the interval stored in memory. I am looking at the "Blink without delay" example but I need something where I can push a button, it will count to a specified number while the controller is running in the background and when the timer is up switch off. The problem I had with the "Blink W/O delay" code is that it runs on an even count where   depending on a count of 1 thousand it is either on or off. my timer is activated by an if then statement.

I need to set millis() to zero and subtract current millis() from the (interval * 1000) and once it equals zero ta-dah! I do not know how to set millis() to zero however

Thank you

Bill
33  Using Arduino / Programming Questions / Re: Passing Values into a function on: May 01, 2011, 11:41:58 pm
Thank you all very much I will try those tips. I am doing this for a design project and am not very strong in programming. It's for an Ethernet enabled programmable dog feeder. The Ethernet code is being developed by another team member.  I am struggling with the timing and the function creation. I constantly write functions but appear to have trouble getting them to work.

I am going to attempt your code examples and will post an updated code tomorrow.

Thanks again

Bill
34  Using Arduino / Programming Questions / Re: Passing Values into a function on: May 01, 2011, 06:48:55 pm
I'm Still pretty new to this. Trying to stumble my way through it. Any suggestions would be greatly appreciated as I am probably embarrassing myself in front of good programmers.

Thanks
35  Using Arduino / Programming Questions / Passing Values into a function on: May 01, 2011, 05:06:58 pm
I am trying to pass a variable "Breakfast" into a function, change the variable and output it as "Time" the variable Breakfast is passed into "Menu Two" and within that I analyze a button state and assign a number to "Breakfast"

I cannot change the value of "Time" or "Breakfast"  I checked the button, it works fine and is normally high. I checked everything else but I cannot output "Breakfast" by returning the variable.

Please help!!!

Thanks

Bill

Code is attached
36  Using Arduino / Networking, Protocols, and Devices / Re: Ds1307 using a MEGA on: February 28, 2011, 03:50:53 pm
Thanks for all the help. At the moment all I want to do is read the time in and compare it with a variable I created. I have it hooked into pins 20 and 21. I've noticed that it does nothing but output zeros either way the pins are connected. Do I hoke the SDA to the SDA and the SCL to the SCL or is it reversed?

I am still very new to the library creation and am painstakingly going through your code line by line. Do you have any example code or is that in the libraries themselves?

Thank you
37  Using Arduino / Networking, Protocols, and Devices / Re: Ds1307 using a MEGA on: February 27, 2011, 10:02:41 pm
One more thing about the code you posted. Why do you proclaim "false" in the serial.print() command? I am not quite understanding this

Thanks
38  Using Arduino / Networking, Protocols, and Devices / Re: Ds1307 using a MEGA on: February 27, 2011, 09:57:35 pm


Where did you get the two libraries? (Excluding the wire)

Thanks again
39  Using Arduino / Networking, Protocols, and Devices / Re: Ds1307 using a MEGA on: February 27, 2011, 09:13:17 pm
That was "line" in the above post. Pins 20 and 21 work. One weird thing though. SparkFun claims they loaded the time onto it already but I am getting 0:00:00 00/00/0000 repeated. Am I looking at the wrong registers?

Thanks again


40  Using Arduino / Networking, Protocols, and Devices / Ds1307 using a MEGA on: February 27, 2011, 07:53:44 pm
Hello all

This is a simple problem but I am trying to just read the date and time from a DS1307 module I purchased from spark fun. I modified the code to only Read the time as they set it properly before shipping.
Code:
#include <Wire.h>

int clockAddress = 0x68;  // This is the I2C address
long previousMillis = 0;  // will store last time Temp was updated
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
byte test;

// Convert normal decimal numbers to binary coded decimal
byte decToBcd(byte val)
{
  return ( (val/10*16) + (val%10) );
}

// Convert binary coded decimal to normal decimal numbers
byte bcdToDec(byte val)
{
  return ( (val/16*10) + (val%16) );
}

// Gets the date and time from the ds1307 and prints result
void getDateDs1307() {
  // Reset the register pointer
  Wire.beginTransmission(clockAddress);
  Wire.send(0x00);
  Wire.endTransmission();

  Wire.requestFrom(clockAddress, 7);

  // A few of these need masks because certain bits are control bits
  second     = bcdToDec(Wire.receive() & 0x7f);
  minute     = bcdToDec(Wire.receive());
 
  // Need to change this if 12 hour am/pm
  hour       = bcdToDec(Wire.receive() & 0x3f); 
  dayOfWeek  = bcdToDec(Wire.receive());
  dayOfMonth = bcdToDec(Wire.receive());
  month      = bcdToDec(Wire.receive());
  year       = bcdToDec(Wire.receive());

  Serial.print(hour, DEC);
  Serial.print(":");
  Serial.print(minute, DEC);
  Serial.print(":");
  Serial.print(second, DEC);
  Serial.print("  ");
  Serial.print(month, DEC);
  Serial.print("/");
  Serial.print(dayOfMonth, DEC);
  Serial.print("/");
  Serial.print(year, DEC);

}


void setup() {
  Wire.begin();
  Serial.begin(57600);
}

void loop() {
      getDateDs1307();
      delay(1000);

}

I am using a Mega and every single tutorial does not have a single decent tip on using this on anything but a single Uno. Can anyone help me with this? I need to be able to read it from pins 20 or 21 (SDA SCL) or 18, 19 (preferably) (TX1 RX1) Can you explain to me how to change this? I am assuming it is a ling in the library

Thanks much

41  Using Arduino / Programming Questions / Re: Incrementing a counter with a momentary pushbutton on: February 22, 2011, 02:46:48 pm
Thank you button library. I couldn't have helped but thought I wasn't the first person to have this problem

Thank you
42  Using Arduino / Programming Questions / Use of Delay on: February 21, 2011, 11:29:22 pm
Thanks again for all your help but I cannot use delay as this is one small piece of code and I need the CPU to be calculating at all times. I have other operations planned

Thanks

Bill
43  Using Arduino / Programming Questions / Re: Incrementing a counter with a momentary pushbutton on: February 21, 2011, 11:12:45 pm
This one works better. Still goes several states when a button is pushed
const int NextButton   = 8;

int TopMenuSelect= 1;

byte NextButtonState   = 0;

byte LastNextButtonState   = 0;


void setup () {
  pinMode(NextButton,   INPUT);
  Serial.begin(2400);
}

void loop () {
  NextButtonState =   digitalRead(NextButton);
 
  if(NextButtonState != LastNextButtonState){
     if(TopMenuSelect == 3){
      TopMenuSelect = 0;
     }
     else{
       TopMenuSelect++;
       Serial.print(TopMenuSelect);
       LastNextButtonState = NextButtonState;
     }
   
    }
 
 
 
   
}//end loop
44  Using Arduino / Programming Questions / Re: Incrementing a counter with a momentary pushbutton on: February 21, 2011, 11:04:57 pm
Here is what I have after trying again

const int NextButton   = 8;

int TopMenuSelect= 1;

byte NextButtonState   = 0;

byte LastNextButtonState   = 0;


void setup () {
  pinMode(NextButton,   INPUT);
  Serial.begin(2400);
}

void loop () {
  NextButtonState =   digitalRead(NextButton);
 
  if(NextButtonState != LastNextButtonState){
    if(NextButtonState = HIGH){
     if(TopMenuSelect == 3){
      TopMenuSelect = 0;
     }
     else{
       TopMenuSelect++;
       Serial.print(TopMenuSelect);
       LastNextButtonState = LOW;
     }
   
    }
  }
 
 
   
}//end loop



The thing goes 123123123 a hundred times in one push

45  Using Arduino / Programming Questions / Re: Incrementing a counter with a momentary pushbutton on: February 21, 2011, 10:43:26 pm
Hello and thanks. This works but in monitoring it with a serial output it increments on the leading edge and the trailing edge thus incrementing the counter twice each button push. Any way to fix this?

Thanks again
Pages: 1 2 [3] 4 5 6