Happy Pi Day! An Arduino Pi Program on TinyScreen

Archimedes of Syracuse (287 BC – 212 BC)) was one of the first to device an algorithm to calculate the value of Pi.

On Pi day we decided to make a simple program to calculate Pi on an Arduino compatible TinyScreen using the Leibnitz formula for Pi.

The Leibniz formula for Pi is: Leibniz Pi

Here is the video of the program:

Here is program code:

//Add TinyScreen Libraries
#include <TinyScreen.h>;
#include <SPI.h>;
#include <Wire.h>;

TinyScreen display = TinyScreen(0); //Initialize TinyScreen

// Initialize the variables
float Pi=0;
float  n=1.0;
unsigned long i=0L;

void setup(void)
{
  Wire.begin();
  display.begin();
  display.setFont(liberationSans_10ptFontInfo);
  display.setCursor(5,1);
}

void loop()
{
 // the recurring calculations of formula
 Pi=Pi+(4.0/n);
 n=n+2.0; // Increment the denominator by 2
 Pi=Pi-(4.0/n);
 n=n+2.0;

 // Print the values
 display.setCursor(22,48);
 display.print(i);
 display.setCursor(5,30);
 display.print(Pi,12);
 delay(5);
 display.setCursor(5,1);
 display.setCursor(12, 14);
 display.print("IoT4kids.com");
 display.setCursor(10,2);
 display.print("Happy Pi Day");

 i=i+1; // Increment the counter
}

References:

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s