Advertisement
jasirgo

Code for numbers Colorduino

Jul 10th, 2013
541
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.28 KB | None | 0 0
  1. //Code for print the numbers from 0 to 99 Colorduino http://zygzax.com/
  2. #include <Colorduino.h>
  3. void setup()
  4. {
  5. Colorduino.Init(); //We startup Colorduino
  6. // White Balance Calibration RGB
  7. unsigned char whiteBalVal[3] = {36,63,63};
  8. Colorduino.SetWhiteBal(whiteBalVal);
  9. }
  10. //CHARACTERS---------------------
  11. byte numbers[10][6][4]={
  12.   {{0,1,1,0},{1,0,0,1},{1,0,0,1},{1,0,0,1},{1,0,0,1},{0,1,1,0}},
  13.   {{0,0,1,0},{0,1,1,0},{0,0,1,0},{0,0,1,0},{0,0,1,0},{0,1,1,1}},
  14.   {{0,1,1,0},{1,0,0,1},{0,0,0,1},{0,0,1,0},{0,1,0,0},{1,1,1,1}},
  15.   {{1,1,1,1},{0,0,1,0},{0,1,0,0},{0,0,1,0},{1,0,0,1},{0,1,1,1}},
  16.   {{0,0,0,1},{0,0,1,1},{0,1,0,1},{1,1,1,1},{0,0,0,1},{0,0,0,1}},
  17.   {{1,1,1,1},{1,0,0,0},{1,1,1,0},{0,0,0,1},{1,0,0,1},{0,1,1,0}},
  18.   {{0,0,1,1},{0,1,0,0},{1,0,0,0},{1,1,1,1},{1,0,0,1},{0,1,1,0}},
  19.   {{1,1,1,1},{0,0,0,1},{0,0,1,0},{0,1,0,0},{1,0,0,0},{1,0,0,0}},
  20.   {{0,1,1,0},{1,0,0,1},{0,1,1,0},{1,0,0,1},{1,0,0,1},{0,1,1,0}},
  21.   {{0,1,1,0},{1,0,0,1},{0,1,1,1},{0,0,0,1},{0,0,1,0},{0,1,0,0}},
  22. };
  23. byte error[6][8]={{0,0,0,0,0,0,0,0},{1,1,1,0,1,1,1,0},{1,0,0,0,1,0,0,1},{1,1,1,0,1,1,1,0},{1,0,0,0,1,0,1,0},{1,1,1,0,1,0,0,1}};
  24. //CHARACTERS END-------------------
  25. //FUNCTIONS------------------------
  26.   //Print an array 3x8x8 (RGB,Rows,Columns)
  27. void PrintMatrix(int data[3][8][8]){
  28.   int f,c;
  29.   for(f=0;f<8;f++){
  30.     for(c=0;c<8;c++){
  31.       if(data[0][f][c]>1||data[1][f][c]>1||data[2][f][c]>1){
  32.         Colorduino.SetPixel(f,c,data[0][f][c],data[1][f][c],data[2][f][c]);
  33.        }
  34.        else{
  35.          Colorduino.SetPixel(f,c,0,0,0);
  36.        }
  37.     }
  38.   }
  39.   Colorduino.FlipPage();
  40. }
  41.   //End of function
  42.   //Change the background color (Run before writing the number)
  43. void Background(int color[3],int out[3][8][8]){
  44.   int f,c,n;
  45.   for(f=0;f<8;f++){
  46.     for(c=0;c<8;c++){
  47.       for(n=0;n<3;n++){
  48.         out[n][f][c]=color[n];
  49.       }
  50.     }
  51.   }
  52. }
  53.   //End of function
  54.   //Write a number up to 2 digits
  55. void Number(int data,int color[3],int out[3][8][8]){
  56.   int f,c,n,u,d;
  57.   if(data>99){
  58.     for(f=0;f<6;f++){
  59.         for(c=0;c<8;c++){
  60.           if(error[f][c]==1){
  61.             for(n=0;n<3;n++){
  62.               out[n][f+1][c]=error[f][c]*color[n];
  63.             }
  64.            }
  65.         }
  66.       }
  67.   }
  68.   else{
  69.     if(data<10){
  70.       for(f=0;f<6;f++){
  71.         for(c=0;c<4;c++){
  72.           if(numbers[data][f][c]==1){
  73.             for(n=0;n<3;n++){
  74.               out[n][f+1][c+2]=numbers[data][f][c]*color[n];
  75.             }
  76.            }
  77.         }
  78.       }  
  79.     }
  80.     else{
  81.       u=data%10;
  82.       d=(data-u)/10;
  83.       for(f=0;f<6;f++){
  84.         for(c=0;c<4;c++){
  85.           if(numbers[d][f][c]==1){
  86.             for(n=0;n<3;n++){
  87.               out[n][f+1][c]=numbers[d][f][c]*color[n];
  88.             }
  89.            }
  90.         }
  91.       }
  92.       for(f=0;f<6;f++){
  93.         for(c=0;c<4;c++){
  94.           if(numbers[u][f][c]==1){
  95.             for(n=0;n<3;n++){
  96.               out[n][f+1][c+4]=numbers[u][f][c]*color[n];
  97.             }
  98.            }
  99.         }
  100.       }
  101.     }
  102.   }
  103. }
  104.   //End of function
  105. //MAIN FUNCTION---------------
  106. void loop(){
  107.   int i;
  108.   int color[3]={63,0,10};
  109.   int background[3]={10,63,20};
  110.   int response[3][8][8];
  111.   for(i=0;i<102;i++){
  112.   Background(background,response);
  113.   Number(i,color,response);
  114.   PrintMatrix(response);
  115.   delay(1000);
  116.   }
  117. }
  118. //END OF MAIN FUNCTION-----------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement