/*
* This is a simple program that uses the
* Leibniz algorithm to calculate the value of Pi
* http://en.wikipedia.org/wiki/Leibniz_formula_for_
*
* This is writted for the O Watch http://theowatch.com
* by O Watch on 14 Mar 2016
*
*/
#include <TinyScreen.h>; //Add TinyScreen Libraries
TinyScreen display = TinyScreen(TinyScreenPlus); //Create the TinyScreen object
// Initialize the variables
float Pi=0;
float n=1.0;
unsigned long i=0L;
void setup(void)
{
display.begin();
display.setFlip(1);
display.setFont(liberationSansNarrow_12ptFontInfo);
display.setCursor(5,1);
display.setCursor(5,2);
display.print("Happy Pi Day");
display.setCursor(15,20);
display.print("Leibniz Pi");
display.setFont(liberationSansNarrow_8ptFontInfo);
}
void loop()
{
// the recurring calculations of Leibniz 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(1,40);
display.print("Pi=");
display.print(Pi,14);
display.setCursor(5,1);
display.setCursor(22,55);
display.print("Count=");
display.print(i);
i=i+1; // Increment the counter
delay(50);
}
Comments
Please log in or sign up to comment.