Calculate the Value of Pi on O Watch

Use the Leibniz algorithm to calculate the value of Pi.

EasyShowcase (no instructions)12 minutes75

Things used in this project

Hardware components

 O Watch Base Kit
×1

Software apps and online services

 Arduino IDE

Code

Leibniz Pi on O Watch

Arduino
```/*
* 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
*
*/

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);
}
```

Credits

O Watch

9 projects • 13 followers
Make your own smartwatch. Learn 3D design and Arduino coding.