Skip to content

Instantly share code, notes, and snippets.

@fgaray
Created June 14, 2013 03:35
Show Gist options
  • Save fgaray/5779284 to your computer and use it in GitHub Desktop.
Save fgaray/5779284 to your computer and use it in GitHub Desktop.
const char PIN[] = {8, 9, 10, 11, 12, 13};
const char NUMERO_PIN = 6;
void setup()
{
for(char i = 0; i < NUMERO_PIN; i++)
{
pinMode(PIN[i], OUTPUT);
digitalWrite(PIN[i], LOW);
}
}
void loop()
{
int n;
for(char i = 0; i < 10;i++)
{
n = fib(i);
mostrar(n);
delay(200);
}
for(char i = 0; i < NUMERO_PIN; i++)
{
digitalWrite(PIN[i], LOW);
}
}
int fib(int n)
{
if(n == 0 || n == 1)
{
return 1;
}else{
return fib(n - 1) + fib(n - 2);
}
}
void mostrar(int n)
{
for(char i = 0; i < NUMERO_PIN; i++)
{
conv(PIN[i], n%2);
n = n / 2;
}
}
int conv(char pin, int n)
{
if(n == 0)
{
digitalWrite(pin, LOW);
}else{
digitalWrite(pin, HIGH);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment