Show Posts
Pages: [1] 2 3
1  Forum 2005-2010 (read only) / Syntax & Programs / Re: Random() Maximum on: November 08, 2007, 08:37:36 pm
Hello,

now everthing is good!
i followed your path Fredrik, it worked. Thanks for that!

@mellis: did you manage fixing the bug in 0010? (I'll keep asking smiley
2  Forum 2005-2010 (read only) / Syntax & Programs / Re: Random() Maximum on: October 19, 2007, 06:47:55 am
Hi
I'm about to try out your suggestions. I'm a bit confused, but i think i'll manage it.
Now i read about the 2's complement math, wich is used for the int values.
Do i shift as well the first bit, the one to sign the value?

greets
w
3  Forum 2005-2010 (read only) / Syntax & Programs / Re: Random() Maximum on: September 10, 2007, 11:09:03 am
Its really great to be at places like this!
Daniel, the pictures of Seoul are looking like the Malls in Shanghai. Fantastic.

@ Mellis: in Arduino 0009 is there still a Bug in Random()?


w

4  Forum 2005-2010 (read only) / Syntax & Programs / Re: Random() Maximum on: August 13, 2007, 12:44:33 am
Thanks man,

you're right, like this it should generate numbers throughout the field i need, thats great.
i'll try this soon. (at the moment i'm in shanghai, for visiting a friend - its the ultimate electronic parts paradise, you find everything you ever dreamed of!!!)

w
5  Forum 2005-2010 (read only) / Syntax & Programs / Re: Random() Maximum on: July 15, 2007, 02:38:46 pm
Thanks for your answer!

this could be a solution. I'll try it.

best

w
6  Forum 2005-2010 (read only) / Syntax & Programs / Re: Random() Maximum on: July 14, 2007, 01:35:01 pm
There is still a problem:
over the serial i get only values until 5 digits.
for evaluation i used this code:

long x;
void setup(){
 Serial.begin(9600);
  }
   void loop(){
     x=random(1576800000L);
     Serial.println (x);
     delay(100);
    }

it returns values until 32 thousand something.
i dont need the serial thing, but i want to be shure if the random numbers are
created throughout the entire range.
is it just a serial problem?

w
7  Forum 2005-2010 (read only) / Syntax & Programs / Re: Random() Maximum on: July 14, 2007, 01:08:53 pm
Thanks!
this very good to know.

w
8  Forum 2005-2010 (read only) / Syntax & Programs / Re: Random() Maximum on: July 14, 2007, 07:27:06 am
at the moment it looks like:

long x = random(1576800000);
(actually its the amount of seconds of 50 years)

so it should look like: long x = random(1576800000L);?


thanks
w

9  Forum 2005-2010 (read only) / Syntax & Programs / Re: Random() Maximum on: July 13, 2007, 07:22:19 pm
mh.
im not shure yet.
i thought about the serial.
What is the maximum value i can transmit over serial?
is it the "int" range?
if it is so, how can i send values of the size of "long" over the serial?
(perhaps i should start another topic for that)

woo
10  Forum 2005-2010 (read only) / Syntax & Programs / Random() Maximum on: July 13, 2007, 06:03:21 pm
Hello there!

I need to create by random really large numbers.
Does the random() function whose type is set as "long", return numbers in the range of long?
between 0 and 2,147,483,647?
when i try to check it by printing the value over serial, it returns always 16807.

any suggestions?
11  Forum 2005-2010 (read only) / Syntax & Programs / Re: aborting a loop on: June 14, 2007, 05:21:17 am
In my opinion you must not use the delay() function for the timing of your LED animation, try using millis() to compare the time how long the leds are already on or of . Then the main loop will continue to run and  you can always read the sensors and set the "val0" varible by your button to zero again.
I copied this from the tutorial section its the "Blinking an LED without using the delay() function" post.
it has to be something like this.
Code:
int ledPin = 13;                // LED connected to digital pin 13
int value = LOW;                // previous value of the LED
long previousMillis = 0;        // will store last time LED was updated
long interval = 1000;           // interval at which to blink (milliseconds)

void setup()
{
  pinMode(ledPin, OUTPUT);      // sets the digital pin as output
}

void loop()
{
  // here is where you'd put code that needs to be running all the time.

  // check to see if it's time to blink the LED; that is, is the difference
  // between the current time and last time we blinked the LED bigger than
  // the interval at which we want to blink the LED.
  if (millis() - previousMillis > interval) {
    previousMillis = millis();   // remember the last time we blinked the LED

    // if the LED is off turn it on and vice-versa.
    if (value == LOW){
      value = HIGH;}
    else{
      value = LOW;}

    digitalWrite(ledPin, value);
  }
}

in general, if you need to abort a running loop you have to write your code into an extra function, which can be called from the main loop check this: http://www.arduino.cc/en/Reference/FunctionDeclaration


hope this helps

w
12  Forum 2005-2010 (read only) / Syntax & Programs / Re: millis() for three years on: May 27, 2007, 12:53:17 pm
Ok it works!
Thanks,

i changed the settings in wiring.c concerning interrupt and phase correct PWM.
since im not really good in programming: can i do this adjustments in the Ardunio code as well e.g.
before the void setup() block:

// enable timer 2 overflow interrupt  

#if defined(__AVR_ATmega168__)                  
      sbi(TIMSK0, TOIE2);
#else
      sbi(TIMSK, TOIE2);
#endif

and now the main routine().....
or is it just allowed to do this in a library?

Now it is about timing stabilty. because it shall run for 3 years. there are about 90 milion seconds....
i guess i have to do some tests.
does the code of main and subroutines affect the stability of the timer?


best
woo


13  Forum 2005-2010 (read only) / Syntax & Programs / Re: millis() for three years on: May 27, 2007, 11:27:20 am
Thanks a lot for the detailed reply!

this sounds good to me to use timer2 in the way you did.
But it is used differently. In wiring.c per default the overflow interrupt isnt enabled and ist is set like timer1 to 8 bit phase correct pwm mode.

why not setting 'microseconds' each time to zero instead subtracting 1000000?

il try out... and post results later.

thanks again

woo
14  Forum 2005-2010 (read only) / Syntax & Programs / millis() for three years on: May 25, 2007, 11:16:57 am
Hi,

I wanna solder a hardware countdown with a time range about 3 years to count back all days:Hours:mins:secs on LED segment displays.
What happens when the millis() function overflows? at which value? does it continue seemlesly?


Woo
15  Forum 2005-2010 (read only) / Interfacing / Re: eeprom download to Mac on: July 09, 2007, 09:30:28 am
what about using the softwareserial to be able to communicate with GPS and the computer same time?
Pages: [1] 2 3