Advertisement
gabbyshimoni

write0-9to7seg

Jan 29th, 2019
348
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.17 KB | None | 0 0
  1. /*
  2.  * 29.01.2019
  3.  * Written by: Gabby Shimoni
  4.  * Description:
  5.  * This program write the digits 0-9 to 7 segment
  6.  */
  7.  
  8. int num_array[10][7] = {  { 1,1,1,1,1,1,0 },    // 0
  9.                           { 0,1,1,0,0,0,0 },    // 1
  10.                           { 1,1,0,1,1,0,1 },    // 2
  11.                           { 1,1,1,1,0,0,1 },    // 3
  12.                           { 0,1,1,0,0,1,1 },    // 4
  13.                           { 1,0,1,1,0,1,1 },    // 5
  14.                           { 1,0,1,1,1,1,1 },    // 6
  15.                           { 1,1,1,0,0,0,0 },    // 7
  16.                           { 1,1,1,1,1,1,1 },    // 8
  17.                           { 1,1,1,0,0,1,1 }};   // 9
  18.                                        
  19. //function header
  20. void Num_Write(int);
  21.  
  22. void setup()
  23. {
  24.   // set pin modes
  25.  for(int k=2;k<9;k++)  pinMode(k, OUTPUT);  
  26. }
  27.  
  28. void loop()
  29. {
  30.   //counter loop
  31.   for (int counter = 0; counter > 10; counter++)
  32.   {
  33.    delay(1000);
  34.    Num_Write(counter);
  35.   }
  36.   delay(3000);
  37. }
  38.  
  39. // this functions writes values to the sev seg pins  
  40. void Num_Write(int number)
  41. {
  42.   int pin= 2;
  43.   for (int j=0; j < 7; j++) {
  44.    digitalWrite(pin, num_array[number][j]);
  45.    pin++;
  46.   }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement