Facebook
From Idiotic Tern, 7 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 297
  1. /*
  2.   Blink
  3.   Turns on an LED on for one second, then off for one second, repeatedly.
  4.  
  5.   Most Arduinos have an on-board LED you can control. On the Uno and
  6.   Leonardo, it is attached to digital pin 13. If you're unsure what
  7.   pin the on-board LED is connected to on your Arduino model, check
  8.   the documentation at http://www.arduino.cc
  9.  
  10.   This example code is in the public domain.
  11.  
  12.   modified 8 May 2014
  13.   by Scott Fitzgerald
  14.  */
  15.  
  16. int pi[21] = {3,1,4,1,5,9,2,6,5,3,5,8,9,7,9,3,2,3,8,4,6};
  17.  
  18. void printSegment(int number) {
  19.         digitalWrite(number, LOW);
  20. }
  21.  
  22. void printDigit(int number) {
  23.         if (number == 0) {
  24.                 printSegment(3);
  25.                 printSegment(4);
  26.                 printSegment(5);
  27.                 printSegment(7);
  28.                 printSegment(8);
  29.                 printSegment(9);
  30.         }
  31.         if (number == 1) {
  32.                 printSegment(3);
  33.                 printSegment(9);
  34.         }
  35.         if (number == 2) {
  36.                 printSegment(4);
  37.                 printSegment(5);
  38.                 printSegment(6);
  39.                 printSegment(9);
  40.                 printSegment(8);
  41.         }
  42.         if (number == 3) {
  43.                 printSegment(4);
  44.                 printSegment(3);
  45.                 printSegment(6);
  46.                 printSegment(9);
  47.                 printSegment(8);
  48.         }
  49.         if (number == 4) {
  50.                 printSegment(7);
  51.                 printSegment(6);
  52.                 printSegment(9);
  53.                 printSegment(3);
  54.         }
  55.         if (number == 5) {
  56.                 printSegment(8);
  57.                 printSegment(7);
  58.                 printSegment(6);
  59.                 printSegment(3);
  60.                 printSegment(4);
  61.         }
  62.         if (number == 6) {
  63.                 printSegment(8);
  64.                 printSegment(7);
  65.                 printSegment(6);
  66.                 printSegment(3);
  67.                 printSegment(4);
  68.                 printSegment(5);
  69.         }
  70.         if (number == 7) {
  71.                 printSegment(3);
  72.                 printSegment(9);
  73.                 printSegment(8);
  74.         }
  75.         if (number == 8) {
  76.                 printSegment(8);
  77.                 printSegment(7);
  78.                 printSegment(6);
  79.                 printSegment(3);
  80.                 printSegment(4);
  81.                 printSegment(5);
  82.                 printSegment(9);
  83.         }
  84.         if (number == 9) {
  85.                 printSegment(8);
  86.                 printSegment(7);
  87.                 printSegment(6);
  88.                 printSegment(3);
  89.                 printSegment(4);
  90.                 printSegment(9);
  91.         }
  92. }
  93. void resetDisplay() {
  94.         for (int i = 2; i < 10; i++) {
  95.                 digitalWrite(i, HIGH);
  96.          }
  97. }
  98.  
  99. // the setup function runs once when you press reset or power the board
  100. void setup() {
  101.   // initialize digital pin 13 as an output.
  102. for (int i = 2; i < 10; i++) {
  103.         pinMode(i, OUTPUT);
  104.         digitalWrite(i, HIGH);
  105.  }
  106. }
  107.  
  108. // the loop function runs over and over again forever
  109. void loop() {
  110.         for (int k = 0; k < 21; k++) {
  111.                         resetDisplay();
  112.                         printDigit(pi[k]);
  113.                         delay(1000);
  114.                 }
  115.  
  116. //printDigit(0);
  117. //digitalWrite(6, HIGH);
  118.   //digitalWrite(2, HIGH);   // turn the LED on (HIGH is the voltage level)
  119.   //delay(1000);              // wait for a second
  120.   //digitalWrite(2, LOW);    // turn the LED off by making the voltage LOW
  121.   //delay(1000);              // wait for a second
  122. }
  123.  
  124. //Unused code
  125.  
  126. /*
  127.  int pi[21] = {3,1,4,1,5,9,2,6,5,3,5,8,9,7,9,3,2,3,8,4,6};
  128.  
  129.         /*
  130.         for (int j = 0; j < 10; j++) {
  131.                 resetDisplay();
  132.                 printDigit(j);
  133.                 delay(1000);
  134.         }
  135.         */
  136.         /*
  137.         for (int k = 0; k < 21; k++) {
  138.                 resetDisplay();
  139.                 printDigit(pi[k]);
  140.                 delay(1000);
  141.         }
  142.         */
  143.  
  144. //printDigit(0);
  145. //digitalWrite(6, HIGH);
  146.   //digitalWrite(2, HIGH);   // turn the LED on (HIGH is the voltage level)
  147.   //delay(1000);              // wait for a second
  148.   //digitalWrite(2, LOW);    // turn the LED off by making the voltage LOW
  149.   //delay(1000);              // wait for a second
  150.  
  151.  */
  152.