Show Posts
Pages: [1]
1  Using Arduino / Programming Questions / Re: Need help with delay on: May 11, 2013, 12:28:24 pm
Per AWOL's remark, I'll wager the original issue with delay was a missing ul suffix.

Which suggests a way you could get help more easily and quickly next time - post your code and describe what's wrong. "It didn't work" doesn't give the folks here much to go on.

I agree and I see your point. I will do my best to provide enough information next time.

I thought you said two minutes?

Code:
delay (120000ul);

I did but I changed my mind. I will have to show this product to an examiner and that the delay works but I don't think he/she want's to wait to minutes for it.
2  Using Arduino / Programming Questions / Re: Need help with delay on: May 11, 2013, 11:41:56 am
I would like to thank you all for your help. I solved the problem with none of your suggestions here's what I did.

Code:
#include <Servo.h>

const int buttonPin = 2;
Servo myservo;

int pos = 0;
int buttonState = 0;
int lastButtonState = 0;

void setup()
{
  pinMode(buttonPin, INPUT);
  myservo.attach(9);
}

void loop()
{
  buttonState = digitalRead(buttonPin);

  if (buttonState != lastButtonState)
  {
    if (buttonState == HIGH)
    {
      for (pos = 0; pos < 180; pos += 1)
      {
        myservo.write(pos);
        delay(15);
      }
      for (pos = 180; pos >=1; pos -=1)
      {
        myservo.write(pos);
        delay(15);
      }
      for (int i = 0; i < 60; i++)
      {
        delay(1000);
      }
    }

  }
  lastButtonState = buttonState;
}




3  Using Arduino / Programming Questions / Re: Need help with delay on: May 11, 2013, 08:15:41 am
I have no idea how to solve this problem at the moment. I have tried "fizzling" around with the milli() and the delay() but none of the things I tried worked out.

As to the layout of my code. I originally learned to program with K&R style and I have sticked to that since. I have never programming in this before only web dev and Python.

Whilst using millis() may be the preferred way to do this as the technique will be needed eventually in a program, the objective of locking out use of the button is easily achieved by using delay()
Code:
start of loop
  if button press detected
    sweep the servo once each way
    delay for 2 minutes (minus the time taken for the servo sweep if you want to be precise)
  end of if
end of loop
Yes, I know that the delay will block the code for 2 minutes, but if it meets the stated requirement, so what ?

I could get that to work, here's my code as it as atm.

Code:
#include <Servo.h>

const int buttonPin = 2; //The number for the pushbutton in
Servo myservo;

int pos = 0; //variable to store the servo position
int buttonState = 0;
int lastButtonState = 0;
long previousMillis = 0;

long interval = 10000;           // interval at which to blink (milliseconds)

void setup()
{
  pinMode(buttonPin, INPUT);
  myservo.attach(9); //attaches the servoon pin 9 to the servo object
}

void loop()
{
  //Read the state of the pushbutton value:

  buttonState= digitalRead(buttonPin);

  if (buttonState != lastButtonState)
  {
      if (buttonState == HIGH){
        for (pos = 0; pos < 180; pos += 1)
        {
          myservo.write(pos);
          delay(15);      
        }
        for (pos = 180; pos >=1; pos -=1)
        {
          myservo.write(pos);
          delay(15);    
        }
      }
      delay(120000);
    }
    lastButtonState = buttonState;
  }
4  Using Arduino / Programming Questions / Re: Need help with delay on: May 11, 2013, 07:13:40 am
Oh sorry here's what I have now:

Code:
#include <Servo.h>
 
const int buttonPin = 2; //The number for the pushbutton in
Servo myservo;
 
int pos = 0; //variable to store the servo position
int buttonState = 0;
int lastButtonState = 0;
long previousMillis = 0;
 
long interval = 10000;           // interval at which to blink (milliseconds)

void setup(){
  pinMode(buttonPin, INPUT);
  myservo.attach(9); //attaches the servoon pin 9 to the servo object
}
 
void loop(){
  //Read the state of the pushbutton value:
 unsigned long currentMillis = millis();

 buttonState= digitalRead(buttonPin);
 if(currentMillis - previousMillis > interval) {
   previousMillis = currentMillis; 
   if (buttonState != lastButtonState) {
     if (buttonState == HIGH){
      for (pos = 0; pos < 180; pos += 1){
        myservo.write(pos);
        delay(15);     
      }
      for (pos = 180; pos >=1; pos -=1){
        myservo.write(pos);
        delay(15);     
      }
    }
   }
   lastButtonState = buttonState;
 }
}
5  Using Arduino / Programming Questions / Re: Need help with delay on: May 11, 2013, 07:06:41 am
Well I tried with the milli() and it does almost... work. The servo motor runs 180 degrees and then return. Now, when I press the button it runs 90 degrees and waits the ten seconds I have told it to and then runs as it should. And that's not what I want it to. I want it to follow the steps I wrote in my previous post.
6  Using Arduino / Programming Questions / Re: Need help with delay on: May 11, 2013, 06:54:33 am
Well I just need this "delay" to work and I'm done with my project. I tried to implement the milli() but now the servo motor runs the half way and stops waits the seconds I have defined and then run the whole way.

- My problem was before that I couldn't get the delay I wanted even though I tried the delay()

Here's what it should do:

1. I press the button
2. The servo motor runs 180 degrees and back again.
3. The delay should prevent me to press the button for the next ten seconds
4. After the ten seconds I should be able to press the button again.

I hope you understand. If I can do this with a single delay please tell me where to implement it since the things I have tried didn't work.
7  Using Arduino / Programming Questions / Re: Need help with delay on: May 11, 2013, 06:46:28 am
I just found that example, I will take a look at it. Thank you!
8  Using Arduino / Programming Questions / Re: Need help with delay on: May 11, 2013, 06:38:47 am
Hmm, thank you for your answer. Do you have an example code or something?

- Do I have to put the whole code into a new if() statement?
9  Using Arduino / Programming Questions / Re: Need help with delay on: May 11, 2013, 06:36:47 am
I have tried the delay() function but it didn't work.
10  Using Arduino / Programming Questions / Need help with delay on: May 11, 2013, 06:33:41 am
I'm currently working on a school project. I have a servo motor which start every time I press a button. That part works but I need a delay so when I press the button once I can't press the button the next 2 minutes.

I hope you guys understand my question otherwise I will be more than happy to explain it again.

Here's my code:

Code:
#include <Servo.h>
 
const int buttonPin = 2; //The number for the pushbutton in
Servo myservo;
 
int pos = 0; //variable to store the servo position
int buttonState = 0;
int lastButtonState = 0;
 
void setup(){
  pinMode(buttonPin, INPUT);
  myservo.attach(9); //attaches the servoon pin 9 to the servo object
}
 
void loop(){
  //Read the state of the pushbutton value:
 buttonState= digitalRead(buttonPin);
 if (buttonState != lastButtonState) {
   if (buttonState == HIGH){
    for (pos = 0; pos < 180; pos += 1){
      myservo.write(pos);
      delay(15);     
    }
    for (pos = 180; pos >=1; pos -=1){
      myservo.write(pos);
      delay(15);     
    }
  }
 }
 lastButtonState = buttonState;
}


11  International / Scandinavia / Re: Hvor kan man købe Arduino Starter Kit? on: January 12, 2013, 01:14:07 pm
Jeg takker jer alle sammen for jeres svar. Jeg tror jeg vælger at gå med www.let-elektronik.dk denne her gang.
12  International / Scandinavia / Hvor kan man købe Arduino Starter Kit? on: January 07, 2013, 04:19:08 am
Jeg er lige begyndt med Arduino, og jeg vil høre hvor i har/eller kan købe et Arduino Starter Kit?

Det skal være dette her: http://arduino.cc/en/Main/ArduinoStarterKit

Det skal helst være en dansk distributør, men udenlandske går an.

 
Pages: [1]