Let's Make Robots!


Calculate the fibonacci sequence.

As the name inplies, Fibonacci uses a basic algorithm to calculate the fibonacci sequence. It is currently running on my Basic Stamp 2, but my goal is to transfer the job to a more powerful processer, AKA my computer. The code which I used is here.


' {$STAMP BS2}

' {$PBASIC 2.5}


a VAR Word

b VAR Word

c VAR Word


a = 1

b = 1

DEBUG "1 1"


  DEBUG " "

  c = a + b


  a = b

  b = c

  PAUSE 1000




The one flaw in my system is that the highest value that a variable can be assigned is 65535, which means that the system goes back to zero when the result of two numbers exceds that value. 


UPDATE (5/18/13):

I have created the JavaScript version of the fibonacci code. Here it is:

var a = 1;

var b = 1;




c = a + b;


for (var c = 1; c < 999999999999; c = a + b)



    a = b;

    b = c;



Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Ooh, yeah!

Here it is in python (I'm attaching a screen grab because I don't know how to do indents here)

And with recursion: 

I wonder if this is what HAL 9000 and Skynet do on thier spare time. :D

That was my original inspiration! In class, we watched "Donald in Mathmagicland", and it covered the golden ratio. My math teacher then explained the relationship between the golden ratio and the fibonacci sequence, inspiring me to come up with the algorith at lunch.

Oh, this is a good one...

In the Cabinet Making world, we call this guy the "Golden Ratio" and it has been indespensable in the carpentry world for hundreds of years. 1.618, yo!

If you happen to have a chest of drawers or a multi-panel door etc, you are likely to find that the dimensions of the drawers decend in size based on ol' Fibonacci. Furniture that is not built according to this Golden Ratio "looks funny".


You will also find that the ratio of distance from your belly button to the ground compared to the distance from your belly button to the top of your head is also a golden ratio.  It keeps turning up in a lot of places.

Computer science teacher uses Fibonacci as one of his examples for how a recursive algorithm works... Pretty poor example according to some but hey, does demonstrate it at least :P I would hate to see it done recursively on a microcontroller. Iteratively as you have done is the only real way forwards for Fibonacci.

An interesting and VERY educational exercise would be to make the stamp calculate longer numbers.  It is quite possible and not that hard.  Every 8 bit processor (AVR/Arduino, Pic/Picaxe, Basic Stamp, etc) that calculates numbers larger than 255 does it.  To get you started here is a web site that shows how to do it on the BS2.



You are an evil man sir, if your suggesting he does it to 64 bits.   ; D

Seriously though it would be good for a 16 bit(up to 65535) attempt at least.