daily pastebin goal
76%
SHARE
TWEET

4 Digit Arduino Counter

Braulio777 Nov 5th, 2013 (edited) 1,615 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //4 Digit Arduino Counter
  2. #define A A4
  3. #define B 13
  4. #define C 10
  5. #define D 9
  6. #define E 8
  7. #define F A1
  8. #define G 11
  9. // Pins driving common anodes
  10. #define CA1 12
  11. #define CA2 A3
  12. #define CA3 A2
  13. #define CA4 A5
  14. // Pins for A B C D E F G, in sequence
  15. const int segs[7] = {A4, 13, 10, 9, 8, A1, 11};
  16. // Segments that make each number
  17. const byte numbers[10] = {0b1000000,0b1111001,0b0100100,0b0110000,0b0011001,0b0010010,0b0000010,0b1111000,0b0000000,0b0010000};
  18.  
  19.  
  20. void setup() {
  21.   pinMode(A4, OUTPUT);
  22.   pinMode(13, OUTPUT);
  23.   pinMode(10, OUTPUT);
  24.   pinMode(9, OUTPUT);
  25.   pinMode(8, OUTPUT);
  26.   pinMode(A1, OUTPUT);
  27.   pinMode(11, OUTPUT);
  28.   pinMode(12, OUTPUT);
  29.   pinMode(A3, OUTPUT);
  30.   pinMode(A2, OUTPUT);
  31.   pinMode(A5, OUTPUT);
  32. }
  33. void loop() {
  34.   for (int digit1=0; digit1 < 10; digit1++) {
  35.     for (int digit2=0; digit2 < 10; digit2++) {
  36.       for (int digit3=0; digit3 < 10; digit3++) {
  37.         for (int digit4=0; digit4 < 10; digit4++) {
  38.       unsigned long startTime = millis();
  39.       for (unsigned long elapsed=0; elapsed < 600; elapsed = millis() - startTime) {
  40.        lightDigit1(numbers[digit1]);
  41.         delay(5);
  42.  lightDigit2(numbers[digit2]);
  43.         delay(5);
  44.         lightDigit3(numbers[digit3]);
  45.         delay(5);
  46.         lightDigit4(numbers[digit4]);
  47.         delay(5);
  48.        }
  49.        }
  50.       }
  51.       }
  52.       }
  53.     }
  54.  void lightDigit1(byte number)      {
  55.   digitalWrite(CA1, LOW);
  56.   digitalWrite(CA2, LOW);
  57.   digitalWrite(CA3, LOW);
  58.   digitalWrite(CA4, HIGH);
  59.   lightSegments(number);
  60.  }
  61. void lightDigit2(byte number) {
  62.   digitalWrite(CA1, LOW);
  63.   digitalWrite(CA2, LOW);
  64.   digitalWrite(CA3, HIGH);
  65.   digitalWrite(CA4, LOW);
  66.   lightSegments(number);
  67. }
  68. void lightDigit3(byte number) {
  69.   digitalWrite(CA1, LOW);
  70.   digitalWrite(CA2, HIGH);
  71.   digitalWrite(CA3, LOW);
  72.   digitalWrite(CA4, LOW);
  73.   lightSegments(number);
  74. }
  75. void lightDigit4(byte number){
  76.   digitalWrite(CA1, HIGH);
  77.   digitalWrite(CA2, LOW);
  78.   digitalWrite(CA3, LOW);
  79.   digitalWrite(CA4, LOW);
  80.   lightSegments(number);
  81.  
  82. }
  83. void lightSegments(byte number){
  84.   for (int i = 0;i < 7;i++) {
  85.     int bit = bitRead(number, i);
  86.     digitalWrite(segs[i], bit);
  87.   }
  88. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top