Loading...
  Show Posts
Pages: 1 2 3 [4] 5 6 ... 14
46  Forum 2005-2010 (read only) / Troubleshooting / Re: I need some help with a decrementing delay on: February 24, 2009, 08:52:40 am
This is more like what I wanted to try.  I guess one of my mistakes here also is that there is no internal pull down resistor, only a pull up.  Therein my lie the problem of the inconsistent decrements.

Thanks for the code.  I like this idea better anyway.  I just didn't know how to do it.  I'll study it.
47  Forum 2005-2010 (read only) / Troubleshooting / I need some help with a decrementing delay on: February 24, 2009, 06:56:28 am
I'm trying to write a routine that will ramp-up the decrement of a value the longer a button is pressed.  It seems that a momentary press, less than my "debounce" delay still decrements about 13 instead of 1.  Can anyone provide some guidance for me?  I really don't understand why it isn't working correctly.

The purpose of this is to act like a clock adjustment.  When you first push the button, the values change slowly.  The longer you hold the button, the faster the numbers change.

Quote

 
//
//
//

int button1 = 11;          //This is my input button
int coarse_value = 1000;   //Eventually, I will have a fine_value adjustment also
int del = 100;             //This is my delay while the button is pressed
int val;                   //The value used for a digital read
void setup()
{
 pinMode(button1,INPUT);
 digitalWrite(button1, LOW); //turn on the internal pulldown
 Serial.begin(9600);         //I'm using serial output for debugging purposes
}

void loop() {

  val = digitalRead(button1);  //Read the value of button1
  delay(50);                   //Wait a short time, a debounce of sorts
  Serial.print("coarse value= ");//print the values for debugging
  Serial.println(coarse_value);
  Serial.print("delay= ");
  Serial.println(del);
if (val == LOW)                //If I release the button, reset the delay
{
  del = 100;
}
if (val == HIGH)               //If I press the button, begin reducing the coarse_value value
{
  coarse_value = (coarse_value-1);
  if (del > 0)
{
  del = (del-1);               //As long as del >0, decriment.  This is the speed ramp-up
  delay(del);                  //for the coarse_value adjustment--the longer it's pressed,
                               //the faster it decriments
}
}

}

 
48  Forum 2005-2010 (read only) / Syntax & Programs / Re: printing a double variable on: January 29, 2009, 11:09:30 am
I've been working with this for several days now.  Something of interest to everyone trying to do this...if you use lcd.print instead of lcdPrintDouble, you will get a binary result on your LCD.  :-?
It was a very simple mistake, but proved to be very frustrating as well.
Have fun!
49  Forum 2005-2010 (read only) / Syntax & Programs / Re: this should be simple, LED stroboscope on: February 27, 2010, 10:56:11 pm
The voltage you read should be between 0 and 5 volts.  The values would be between 0 and 1023.  You could use the map function;  map(value, fromLow, fromHigh, toLow, toHigh) to correlate between the value read from the potentiometer and the delay time you desire.  Does this help?
50  Forum 2005-2010 (read only) / Syntax & Programs / Re: Poor coding structure--need help on: April 22, 2009, 07:06:03 pm
That's kind of what I'm getting from one of our software engineers at work.  She has suggested using routines that test states and change variables.  Once the variable is processed, change it back to its original state, for example.  I'll get back to you.
51  Forum 2005-2010 (read only) / Syntax & Programs / Re: Poor coding structure--need help on: April 21, 2009, 05:48:55 am
Here is what I have at this time.  I'm trying to get these 3 menus to work.  There is some code that has been commented out.  That was some stuff that I was trying, but had even less success with.  Once I get the menus working, I'll move on, so here's what I have so far:


Code:
#include <LiquidCrystal.h>

//This is a short program to explore a method of using delay timing to
//cause a value to incriment slowly until the button has been held down
//for a period of time, after which it will incriment much faster
//The initial delay is reset if the button is released

//LiquidCrystal(rs, rw, enable, d0, d1, d2, d3)
//My Display pinout(rs-4, rw-5, enable-6, d0-11, d1-12, d2-13, d3-14)

LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);

int backBtn = 14;          //These are the input buttons
int incBtn = 15;
int decBtn = 17;
int nextBtn = 18;
int selectBtn = 16;
int milliSeconds = 0;     //starting value for milliSeconds
int microSeconds = 0;
int del = 10;             //This is my delay while the button is pressed
int back;                 //The values used for a digital read
int inc;
int dec;
int next;
int select;
int debounce = 20;        //button debounce time
int state = 0;

void setup()
  {
   pinMode(backBtn,INPUT);         //set pin as input
   digitalWrite(backBtn, HIGH);    //turn on the internal pull-up
   pinMode(incBtn,INPUT);
   digitalWrite(incBtn, HIGH);     //turn on the internal pull-up
   pinMode(selectBtn,INPUT);
   digitalWrite(selectBtn, HIGH);  //turn on the internal pull-up
   pinMode(decBtn,INPUT);
   digitalWrite(decBtn, HIGH);     //turn on the internal pull-up
   pinMode(nextBtn,INPUT);
   digitalWrite(nextBtn, HIGH);    //turn on the internal pull-up
   constrain(del, 0, 10);          //limit the range of values for del
   constrain(milliSeconds, 0, 999); //limit the range of values for milliSeconds
   constrain(microSeconds, 0, 999);  
   constrain(state, 0, 2);
}

void loop()
  {
//    lcd.clear();
//    lcd.print("Hi-Speed Camera");
//    lcd.setCursor(0,1);
//    lcd.print("  delay timer");
//    delay(3000);
//    lcd.clear();
    currentState();         //go to the first menu -- choose the milliseconds value
        if(state == 0)
      {
        choosemilliSeconds();
      }
    if(state == 1)
      {
        choosemicroSeconds();
      }
    if(state == 2)
      {
        showTotalTime();
      }

  }                               //close void loop

void btnPressed()
  {
    if (del > 0)                //if del value is greater than 0, we want
      {                         // to delay a bit to increment more slowly
        del=(del-1);
        delay(250);
      }
  }                            //close void btnPressed
  
void printRightArrow()
  {
    lcd.setCursor(11,1);
    lcd.print("next");
    lcd.write(0b01111110);
  }

void printLeftArrow()
  {
    lcd.setCursor(0,1);
    lcd.write(0b01111111);
    lcd.print("back");
  }

void printmilliSeconds()
  {
    lcd.setCursor(0,0);
    if (milliSeconds < 100)
      {
        lcd.print("0");        //add zeroes as place holders on the display
      }
    if (milliSeconds <10)
      {
        lcd.print("0");
      }
      lcd.print(milliSeconds);  //print the current value on the display
      lcd.print(" msec");
  }
  
void choosemilliSeconds()
  {
    readBtns();
    while(next == HIGH)
    {
    readBtns();
    printmilliSeconds();
    printRightArrow();
    if (dec == LOW)               //If I press the decriment button, begin reducing the milliSeconds value
    {
      if(milliSeconds >0)
        {
          milliSeconds = (milliSeconds-1);
        }
      btnPressed();
    }

  if (inc == LOW)               //If I press the incriment button, begin increasing the milliSeconds value
     {
      if(milliSeconds <999)
        {
          milliSeconds = (milliSeconds+1);
        }
      btnPressed();
     }
    }
  readBtns();
/*  if(next == LOW)
  {
    choosemicroSeconds();
  }*/                             //close While loop
  }                             //close void choosemilliSeconds
  
void readBtns()
  {
    back = digitalRead(backBtn);      //Read the value of backBtn
    next = digitalRead(nextBtn);      //Read the value of nextBtn
    select = digitalRead(selectBtn);  //Read the value of selectBtn
    inc = digitalRead(incBtn);        //Read the value of incBtn
    dec = digitalRead(decBtn);        //Read the value of decBtn
    delay(debounce);                  //Wait a short time
    
    if (back == HIGH && next == HIGH && inc == HIGH && dec == HIGH && select == HIGH)
      {
        del = 10;                 //if no buttons are pressed, del is set to 10
      }

  }
void choosemicroSeconds()
  {
    readBtns();
    while(back == HIGH && next == HIGH)
   {
     readBtns();
    printmicroSeconds();
    printLeftArrow();
    printRightArrow();
    if (dec == LOW)               //If I press the decriment button, begin reducing the milliSeconds value
    {
      if(microSeconds >0)
        {
          microSeconds = (microSeconds-1);
        }
      btnPressed();
    }

  if (inc == LOW)               //If I press the incriment button, begin increasing the milliSeconds value
    {
      if(microSeconds <999)
        {
          microSeconds = (microSeconds+1);
        }
      btnPressed();
    }
    }                          //close While loop  
/*     readBtns();
    
  if(next == LOW)
  {
//   lcd.clear();
   showTotalTime();
  }
  if(back == LOW)
  {
//    lcd.clear();
    choosemilliSeconds();
  }*/
  }                          //close void choosemicroSeconds
  
void printmicroSeconds()
  {
    lcd.setCursor(0,0);
    if (microSeconds < 100)
      {
        lcd.print("0");        //add zeroes as place holders on the display
      }
    if (microSeconds <10)
      {
        lcd.print("0");
      }
      lcd.print(microSeconds);  //print the current value on the display
      lcd.print(" usec");
   }                            //close void printmicroSeconds


void showTotalTime()          //show the total delay time
  {
    readBtns();
    while(back == HIGH && next == HIGH)
   {
     readBtns();
    printLeftArrow();
    printRightArrow();
    lcd.setCursor(0,0);
   lcd.print("0.");
   if (milliSeconds < 100)
      {
        lcd.print("0");        //add zeroes as place holders on the display
      }
    if (milliSeconds <10)
      {
        lcd.print("0");
      }
      lcd.print(milliSeconds);  //print the current value on the display

   lcd.print(",");

   if (microSeconds < 100)
      {
        lcd.print("0");        //add zeroes as place holders on the display
      }
    if (microSeconds <10)
      {
        lcd.print("0");
      }
      lcd.print(microSeconds);  //print the current value on the display
      lcd.print(" sec");
   }                             //close While loop

/*     readBtns();
    
  if(next == LOW)
  {
   lcd.clear();
   choosemilliSeconds();
  }
  if(back == LOW)
  {
    lcd.clear();
    choosemicroSeconds();
  }*/
 }                              //close showTotalTime

void currentState()
  {
    readBtns();
    delay(debounce);
    if(back == LOW)
      {
        state = state-1;
      }
    if(next == LOW)
      {
        state = state-1;

//        return;
      }
  }
52  Forum 2005-2010 (read only) / Syntax & Programs / Re: Poor coding structure--need help on: April 19, 2009, 02:45:01 pm
I think I have this thing figured out.  I think my debounce time was too short.  I increased the time and I seem to have all of the menus that I expected to have.  I'll play with it some more and let you know how it goes.  Thanks for your help.
53  Forum 2005-2010 (read only) / Syntax & Programs / Poor coding structure--need help on: April 17, 2009, 08:19:43 pm
Before arduino, I've never used C.  My prior experience, which is mainly fortran, pascal, basic, and assembly, is from classes in school and not really for real life interfacing, etc.  My delimma is this: I believe I need a state machine structure.  I think I'm on the right track, but I need an experienced coding jedi to steer me in the right direction.  Attached is my program.  I'm trying to enter values in the first two menus and then show the total value in the last menu.  I think I'm close, but my program gets stuck somewhere.  Any help would be greatly appreciated.
Quote

#include <LiquidCrystal.h>
//This is a short program to explore a method of using delay timing to
//cause a value to incriment slowly until the button has been held down
//for a period of time, after which it will incriment much faster
//The initial delay is reset if the button is released
//LiquidCrystal(rs, rw, enable, d0, d1, d2, d3)
//My Display pinout(rs-4, rw-5, enable-6, d0-11, d1-12, d2-13, d3-14)
LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);
int backBtn = 14;          //These are the input buttons
int incBtn = 15;
int decBtn = 17;
int nextBtn = 18;
int selectBtn = 16;
int milliSeconds = 0;     //starting value for milliSeconds
int microSeconds = 0;
int del = 10;             //This is my delay while the button is pressed
int back;                 //The values used for a digital read
int inc;
int dec;
int next;
int select;
int debounce = 20;        //button debounce time
int state = 0;
void setup()
  {
   pinMode(backBtn,INPUT);         //set pin as input
   digitalWrite(backBtn, HIGH);    //turn on the internal pull-up
   pinMode(incBtn,INPUT);
   digitalWrite(incBtn, HIGH);     //turn on the internal pull-up
   pinMode(selectBtn,INPUT);
   digitalWrite(selectBtn, HIGH);  //turn on the internal pull-up
   pinMode(decBtn,INPUT);
   digitalWrite(decBtn, HIGH);     //turn on the internal pull-up
   pinMode(nextBtn,INPUT);
   digitalWrite(nextBtn, HIGH);    //turn on the internal pull-up
   constrain(del, 0, 10);          //limit the range of values for del
   constrain(milliSeconds, 0, 999); //limit the range of values for milliSeconds
   constrain(microSeconds, 0, 999);  
   constrain(state, 0, 2);
}

void loop()
  {
//    lcd.clear();
//    lcd.print("Hi-Speed Camera");
//    lcd.setCursor(0,1);
//    lcd.print("  delay timer");
//    delay(3000);
//    lcd.clear();
    currentState();         //go to the first menu -- choose the milliseconds value
        if(state == 0)
      {
        choosemilliSeconds();
      }
    if(state == 1)
      {
        choosemicroSeconds();
      }
    if(state == 2)
      {
        showTotalTime();
      }
  }                               //close void loop

void btnPressed()
  {
    if (del > 0)                //if del value is greater than 0, we want
      {                         // to delay a bit to increment more slowly
        del=(del-1);
        delay(250);
      }
  }                            //close void btnPressed
  
void printRightArrow()
  {
    lcd.setCursor(11,1);
    lcd.print("next");
    lcd.write(0b01111110);
  }
void printLeftArrow()
  {
    lcd.setCursor(0,1);
    lcd.write(0b01111111);
    lcd.print("back");
  }

void printmilliSeconds()
  {
    lcd.setCursor(0,0);
    if (milliSeconds < 100)
      {
        lcd.print("0");        //add zeroes as place holders on the display
      }
    if (milliSeconds <10)
      {
        lcd.print("0");
      }
      lcd.print(milliSeconds);  //print the current value on the display
      lcd.print(" msec");
  }
void choosemilliSeconds()
  {
    readBtns();
    while(next == HIGH)
    {
    readBtns();
    printmilliSeconds();
    printRightArrow();
    if (dec == LOW)               //If I press the decriment button, begin reducing the milliSeconds value
    {
      if(milliSeconds >0)
        {
          milliSeconds = (milliSeconds-1);
        }
      btnPressed();
    }
  if (inc == LOW)               //If I press the incriment button, begin increasing the milliSeconds value
     {
      if(milliSeconds <999)
        {
          milliSeconds = (milliSeconds+1);
        }
      btnPressed();
     }
    }
  readBtns();
/*  if(next == LOW)
 {
   choosemicroSeconds();
 }*/                             //close While loop
  }                             //close void choosemilliSeconds
void readBtns()
  {
    back = digitalRead(backBtn);      //Read the value of backBtn
    next = digitalRead(nextBtn);      //Read the value of nextBtn
    select = digitalRead(selectBtn);  //Read the value of selectBtn
    inc = digitalRead(incBtn);        //Read the value of incBtn
    dec = digitalRead(decBtn);        //Read the value of decBtn
    delay(debounce);                  //Wait a short time
    if (back == HIGH && next == HIGH && inc == HIGH && dec == HIGH && select == HIGH)
      {
        del = 10;                 //if no buttons are pressed, del is set to 10
      }
  }
void choosemicroSeconds()
  {
    readBtns();
    while(back == HIGH && next == HIGH)
   {
     readBtns();
    printmicroSeconds();
    printLeftArrow();
    printRightArrow();
    if (dec == LOW)               //If I press the decriment button, begin reducing the milliSeconds value
    {
      if(microSeconds >0)
        {
          microSeconds = (microSeconds-1);
        }
      btnPressed();
    }

  if (inc == LOW)               //If I press the incriment button, begin increasing the milliSeconds value
    {
      if(microSeconds <999)
        {
          microSeconds = (microSeconds+1);
        }
      btnPressed();
    }
    }                          //close While loop  
/*     readBtns();
   
 if(next == LOW)
 {
//   lcd.clear();
  showTotalTime();
 }
 if(back == LOW)
[color=#7
54  Forum 2005-2010 (read only) / Interfacing / Re: Considering Gobetwino on: December 27, 2010, 10:03:02 am
Thanks, that helps.  It's hard to tell from the information on their site just how it works.  Either I haven't read into it enough, or it needs some good hand-holding examples for people like me.  smiley-wink
55  Forum 2005-2010 (read only) / Interfacing / Considering Gobetwino on: December 26, 2010, 06:02:19 pm
I have a job I think may be appropriate for Arduino and Gobetwino, but am not sure.  Here's what I'm thinking...I have a remote access device that, from time to time, needs to be rebooted.  I could do one of a few things here, but I'm thinking I'd like to set up a secure shell to my pc and use Gobetwino to tell the Arduino to switch a relay, resetting the device.

Any thoughts?  How difficult would this be?

Other option is to have Arduino "watch" an LED for a blink code.  When a certain code appears, it switches the relay.  This is probably easier, really, but I like the idea of Gobetwino, and it opens the door for other options as well.
56  Forum 2005-2010 (read only) / Interfacing / Re: Temperature/Humidity Sensor Wire Length (SHT11) on: November 22, 2010, 12:27:57 pm
You can increase the distance if you slow down SPI.  See this thread, reply #7 for details:  http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1229870415
57  Forum 2005-2010 (read only) / Interfacing / Re: HTML Buttons on: November 07, 2010, 08:15:33 pm
In the short term, I agree.  Just thought it would be nice to have another resource to peruse for info.
58  Forum 2005-2010 (read only) / Interfacing / Re: HTML Buttons on: November 07, 2010, 09:12:26 am
In Busted Duck's defense, I have found myself in the same situation.  I bought an Arduino, got started with some simple examples and started brainstorming.  I then had the same problem as Duck...I was getting into projects that were a little more complex than my level of understanding would allow me to accomplish.

The good part about all of this is that I have continued to learn and my crazy projects have pushed me to learn more than I knew before I started the project.  I think that is part of what the Arduino platform is all about.

Action Item: Unfortunately, I am not qualified to do this, but if someone were willing to write a short manual that could be used for beginners.  I have the Arduino notebook, which is a great tool.  What I have in mind is probably multiple notebooks like the Arduino Notebook.  It could be used to lead a beginner through important building blocks in their knowledge base.  One could be written about Arduino HTML, for example.  There is a plethora of subjects to be written about, but it could be like a workbook, which could have example programs that could get someone started and some code snippets that show how to accomplish different tasks.  I don't suggest that this would provide a complete program, so the "student" would still have work to do.  I just think it would be a good start and point of reference for beginners.
59  Forum 2005-2010 (read only) / Interfacing / Re: sending the values of accelerometers to excel on: September 29, 2010, 08:16:43 pm
I have only just tried this, but it seems to work well.  http://www.parallax.com/ProductInfo/Microcontrollers/BASICStampSoftware/StampPlotSoftware/tabid/481/Default.aspx
60  Forum 2005-2010 (read only) / Interfacing / Re: Arduino + Processing--need help on: August 06, 2010, 07:06:31 am
Well, after downloading a different arduino library for processing, this finally works.  I sure couldn't tell you why, but I'm happy to say that I can move on with my project.  Paul, thanks for your time and patience.  I appreciate your attention.
Pages: 1 2 3 [4] 5 6 ... 14