Skip to content

Instantly share code, notes, and snippets.

@mandulaj
Last active October 27, 2015 12:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mandulaj/62359e966c778234e542 to your computer and use it in GitHub Desktop.
Save mandulaj/62359e966c778234e542 to your computer and use it in GitHub Desktop.
Pi counter for ATtiny84
/* picounter.c
Counts digits of pi in binary.
*/
void setup() {
pinMode(0, OUTPUT);
pinMode(1, OUTPUT);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
}
int pi[] = {3,1,4,1,5,9,2,6,5,3,5,8,9,7,9,3,2,3,8,4,6,2,6,4,3,3,8,3,2,7,9,5,0,2,8,8,4,1,9,7,1,6,9,3,9,9,3,7,5,1,0,5,8,2,0,9,7,4,9,4,4,5,9,2,3,0,7,8,1,6,4,0,6,2,8,6,2,0,8,9,9,8,6,2,8,0,3,4,8,2,5,3,4,2,1,1,7,0,6,7,9,8,2,1,4,8,0,8,6,5,1,3,2,8,2,3,0,6,6,4,7,0,9,3,8,4,4,6,0,9,5,5,0,5,8,2,2,3,1,7,2,5,3,5,9,4};
int len = 146;
int power2(int n) {
int ret = 1;
for (int i = 0; i < n; i++) {
ret *= 2;
}
return ret;
}
int displayNum(int n) {
for (int i = 0; i<4; i++) {
int mask = power2(i);
if ((n & mask) == mask) {
digitalWrite(i, HIGH);
} else {
digitalWrite(i, LOW);
}
}
}
int i = 0;
void loop() {
for (i = 0; i<len; i++) {
displayNum(pi[i]);
delay(1000);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment