MyException - 我的异常网
当前位置:我的异常网» J2SE » java 模拟led屏展示

java 模拟led屏展示(2)

www.MyException.Cn  网友分享于:2013-11-09  浏览:1015次

      for (int i = ROW / 2; i < ROW; i++)
        chs[i][COL - 1] = FILL_CHAR;
    if (b[3])
      for (int i = 0; i < COL; i++)
        chs[ROW - 1][i] = FILL_CHAR;
    if (b[4])
      for (int i = ROW / 2; i < ROW; i++)
        chs[i][0] = FILL_CHAR;
    if (b[5])
      for (int i = 0; i <= ROW / 2; i++)
        chs[i][0] = FILL_CHAR;
    if (b[6])
      for (int i = 0; i < COL; i++)
        chs[ROW / 2][i] = FILL_CHAR;
    return chs;
  }

  /**
  *
  * 译码器
  *
  *    0
  *  #######
  *  #  # 1
  *  5 #  6  #
  *  #######
  *  #  #
  *  4 #  # 2
  *  #######
  *    3
  *   
  * 0 表示 leds[0],若为 true 表示该 LED 显示,否则不显示
  *
  * @param num
  * @return
  */
  private boolean[] getLed(int num) {   
    boolean a = (num & 8) >>> 3 == 1;
    boolean b = (num & 4) >>> 2 == 1;
    boolean c = (num & 2) >>> 1 == 1;
    boolean d = (num & 1) == 1;
    boolean[] leds = new boolean[7];
    leds[0] = a | (!a & c) |(!a & !b & !c & !d) | (!a & b & !c & d);
    leds[1] = a | (!a & !b) | (!a & b & c & d) | (!a & b & !c & !d); 
    leds[2] = a | b | !c | d;
    leds[3] = a | (!a & !b & c) | (!a & !b & !c & !d) | (!a & b & c & !d) |
        (!a & b & !c & d);
    leds[4] = (!a & c & !d) | (!b & !c & !d);
    leds[5] = a | (!a & !b & !c & !d) | (!a & b & !d) | (!a & b & !c & d);
    leds[6] = a | (!a & !b & c) | (!a & b & !c) | (!a & b & c & !d);
    return leds;
  }
}

这个就可以输出我们常见的七段 LED 数字了:

Java code
#######       # ####### ####### #     # ####### ####### ####### ####### #######
#     #       #       #       # #     # #       #             # #     # #     #
#     #       #       #       # #     # #       #             # #     # #     #
#     #       # ####### ####### ####### ####### #######       # ####### #######
#     #       # #             #       #       # #     #       # #     #       #
#     #       # #             #       #       # #     #       # #     #       #
#######       # ####### #######       # ####### #######       # ####### #######

文章评论

软件开发程序错误异常ExceptionCopyright © 2009-2015 MyException 版权所有