Show Posts
Pages: 1 ... 30 31 [32] 33 34 ... 252
466  Using Arduino / Project Guidance / Re: help to create remote controled count down on: June 30, 2014, 12:31:32 pm
Here is a simple count down timer.
Code:
long time = millis();
int M,Min, S, Sec;
boolean Reset = false, Stop = false, Paused = false;
volatile boolean timeFlag = false;

void setup()
{
  Serial.begin(115200);
  StartTimer(0,10);   
  // if minutes is set to NULL, it will be give a default value of 0, otherwise minutes will be set to input value
  // seconds is basically the same but its default value is 59
}

void loop()
{
  if( !CountDownTimer() ) // check if the timer has reached 0
  {
    //ResetTimer(); // if it has, reset the timer. *OPTIONAL*
  } 

  if(TimeHasChanged() ) // this prevents the time from being constantly shown.
  {
    Serial.print(ShowMinutes());
    Serial.print(":");
    Serial.println(ShowSeconds()); // This DOES NOT format the time to 0:0x when seconds is less than 10.
    // if you need to format the time to standard format, use the sprintf() function.
  }
 
  StopTimerAt(0,2); // With this, you can stop the timer at any minute or second
}

boolean CountDownTimer()
{
  timeFlag = false;
  if(!Stop && !Paused) // if not Stopped or Paused, run the timer
  {
    if(millis() - time > 1000) // check the time difference and see if 1 second has elapsed
    {
      time = millis(); // 1 second HAS elapsed, so reset the time variable
      S > 0? S-- : (M-- , S = 59); // Check to see if S can be decremented and is still above 0.
      // If S goes below 0, reset it back to 59 and decrement M by
      timeFlag = true;

      if(M == 0 && S == 0) // check to see if both M and S are 0
          Stop = true; // If so, stop the timer
    }
  }
  return !Stop; // return the state of the timer
}

void ResetTimer()
{
  StartTimer(Min, Sec);
  Stop = false;
}

void StopTimer()
{
  Stop = true;
}

void StopTimerAt(int minutes, int seconds)
{
  if(minutes == ShowMinutes() && seconds == ShowSeconds())
    Stop = true;
}

void PauseTimer()
{
  Paused = true;
}

void ResumeTimer() // You can resume the timer if you ever stop it.
{
  Paused = false;
}

void StartTimer(int minutes, int seconds)
{
  Min = minutes; // set to global vars
  Sec = seconds; // ------------------
 
  (minutes == NULL) ? M = 0 : (M = minutes - 1);
  (seconds == NULL) ? S = 60: (S = seconds);
  Stop = false;
}

int ShowMinutes()
{
  return M;
}

int ShowSeconds()
{
  return S;
}

boolean TimeHasChanged()
{
  return timeFlag;
}

boolean TimeCheck(int minutes, int seconds) // output is true if timer equals requested time
{
  return (minutes == ShowMinutes() && seconds == ShowSeconds());
}
467  Using Arduino / Project Guidance / Re: help to create remote controled count down on: June 30, 2014, 07:51:29 am
This is easy enough to where you can write the code, but I can make a sample you can learn from.
468  Using Arduino / Project Guidance / Re: help to create remote controled count down on: June 29, 2014, 10:02:04 pm
You will need to add the rest of the numbers 0 - 9 and do some math to see what values you need to show based on the counter.

There should be pre-built 7 segment displays that have a library you can use to get them to work. This might be easier for you then wiring everything up and hoping for the best. But that's up to you.

As for you displays, (depending what you do) you need to look at the counter and see if it is greater or less than 10. This will tell your code what to display on each 7 segment disp. The first display will show 0 - 9 and the second will only show 0 and 1.

Quote
if i want to create a big  7 segment  using 5 led/segment
Get a prebuilt display for this.
469  Using Arduino / Project Guidance / Re: help to create remote controled count down on: June 29, 2014, 08:27:12 pm
You add it where you need to, whatever button you want to use to reset it.
I don't know the IR button codes.
470  Using Arduino / Project Guidance / Re: help to create remote controled count down on: June 29, 2014, 08:15:26 pm
Quote
i want to change the code to add reset function ( make the counter 0)

I added it while you are typing.
471  Using Arduino / Project Guidance / Re: help to create remote controled count down on: June 29, 2014, 08:03:45 pm
A single 7 segment display? Where is that in your code? Or are you setting the display with pin 2 - 8?

I cleaned up your code a little bit.

Code:
#include <IRremote.h>

int RECV_PIN = 11;

IRrecv irrecv(RECV_PIN);

decode_results results;

byte numbers[] = {
  B0010000, B1011011, B0001100, B0001001, B1000011 }; // insert the rest of the display values here

long time = millis();
byte idx = 0;

void setup()
{
  Serial.begin(9600);
  for(byte i = 2; i < 9; i++)
    pinMode(i, OUTPUT);
  irrecv.enableIRIn(); // Start the receiver
}

void loop()
{
  if (irrecv.decode(&results))
  {
    Serial.println(results.value );
    if(results.value==2706322374)
    {
      decompteur(4);
      irrecv.resume(); // Receive the next value
    }
    else if(results.value==1231570528)
    {
      decompteur(2);
      irrecv.resume(); // Receive the next value
    }
    irrecv.resume(); // Receive the next value
  }
}

void decompteur(byte n)
{
  if( millis() - time >= 60*1000)
  {
    if(idx < n)
    {
      for(byte num = 0; num < 7; num++)
        digitalWrite(num+2, bitRead(numbers[n - idx], num) );
      idx++;
    }
    else
      idx = 0;

    time = millis();
  }
}

void resetCounter() // call this function to reset the counter back to zero if you need to.
{
  idx = 0;
}
472  Using Arduino / Project Guidance / Re: help to create remote controled count down on: June 29, 2014, 07:33:16 pm
What does the count down timer control? Is it on for the set time duration or does it start once the timer is done?
473  Using Arduino / Project Guidance / Re: help to create remote controled count down on: June 29, 2014, 06:50:56 pm
Where is the code you made or have?
474  Using Arduino / Project Guidance / Re: Stepper Motor Help on: June 29, 2014, 06:30:46 pm
But does the stepper move?

Quote
The run() function will try to move the motor (at most one step per call) from the current position to the target position set by the most recent call to this function. Caution: moveTo() also recalculates the speed for the next step. If you are trying to use constant speed movements, you should call setSpeed() after calling moveTo().


Add this instead.
Serial.print(val);
Serial.print(" ");
Serial.println(stepper1.currentPosition());
475  Using Arduino / Project Guidance / Re: help to create remote controled count down on: June 29, 2014, 06:22:17 pm
Sure.

The delay function should not be used when you are waiting for something else to happen. IE,
Quote
i cant get reset commande from the ir remote ; i get it only if the delay finish
Because it results in this happening.

So delay(10*60*1000) is going to block you from doing anything for 10 minutes. This is 10 minutes of wasted time when the Arduino could be doing something else while its waiting for the 10 minutes to elapse.

You want to use a non blocking method like the one used in the Arduino example "Blink Without Delay". In this example, it shows you how to do something without waiting for something else to be finished. This is the Arduinos way of multitasking on a single thread processor.
476  Using Arduino / Project Guidance / Re: Stepper Motor Help on: June 29, 2014, 06:13:40 pm
These go in the setup() function:
Code:
stepper1.setMaxSpeed(1000.00);
  stepper1.setAcceleration(900.0);
  stepper1.setSpeed(350);

This value is never changing:
  Serial.println(currentPos);

What does this show?
  Serial.println(val);

Take a look at the examples provided with this library. AccelStepper
477  Using Arduino / Project Guidance / Re: help to create remote controled count down on: June 29, 2014, 06:06:18 pm
Delay() blocks the code from doing anything until it is done, so you need a non-blocking method. Look into the example sketch, Blink Without Delay.
478  Using Arduino / Programming Questions / Re: Reading serial data without 'terminator' on: June 28, 2014, 10:50:45 pm
What about encapsulating the data within these <. . .>. As long as you send < first and receive > last, your data should be fine.

There are plenty of topics in this forum that get data with this method.
479  Using Arduino / Programming Questions / Re: rgb led flickering when on: June 28, 2014, 09:05:41 pm
Edit: I caught it.

You do know what PWM stands for right? Pulse Width Modulation. The digital pins (with the ~ symbol using analogWrite() ) output a pulse based on a timer that takes a parameter value 0 - 255. The higher the number, the more the pulses come out HIGH, the lower the number, the more the pulses come out LOW.

So your flickering is due to those lower pulses. The way you would fix this issue is with a diode and capacitor.
The diode prevents backfeed and protects the arduino, and the capacitor stores the charge level.

Try it, a standard 1N4001 diode and a 10uf cap should be enough.
480  Using Arduino / Project Guidance / Re: First robot--motor to wheel help on: June 28, 2014, 08:57:28 pm
When in doubt, Legos or Erector Set.

Or if you really want to build your chassis, you can use wood or other such materials.
Pages: 1 ... 30 31 [32] 33 34 ... 252