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: ![]()
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: