Beispiel #1
0
 /**
  * Display a single character right to left
  *
  * @param character The character to be displayed
  */
 public void displayCharacterBackward(char character) {
   try {
     dots = font.getChar(character);
     for (int i = dots.length - 1; i >= 0; i--) {
       bltLEDs(dots[i]);
       // System.out.print(character);
       Thread.sleep(1);
     }
     bltLEDs(0);
     Thread.sleep(1);
   } catch (InterruptedException ex) {
     ex.printStackTrace();
   }
 }
Beispiel #2
0
  /**
   * Scroll a string across the swinging display
   *
   * @param string The string to display
   * @param scrollrate The speed to scroll at. To be readable, this should be a value from 1 to 10.
   */
  public void scroll(String string, int scrollrate) {
    long start = System.currentTimeMillis();
    long left = start;
    long right = start;
    int overhead = 140; // The magic values of overhead and gap
    int gap = 170; // were set empirically
    int i, j, offset = overhead;
    int len = string.length();
    int mapSize = 0;
    int[] bitmap;
    boolean lefting = false; // debug

    System.out.println("start scrolling " + string);

    // find the length of the bitmap
    for (i = 0; i < len; i++) {
      mapSize += (font.getCharWidth(string.charAt(i))) + 1;
    }

    // create a custom length array to hold the bitmap
    bitmap = new int[mapSize + (2 * overhead)];

    for (i = 0; i < bitmap.length; i++) bitmap[i] = 0;

    // preload the bitmap for the whole string
    // this is probably a bad idea memory-wse, but I'm in a hurry
    for (i = 0; i < len; i++) {
      int[] character = font.getChar(string.charAt(i));
      for (j = 0; j < character.length; j++) {
        bitmap[offset++] = character[j];
      }
      bitmap[offset++] = 0;
    }

    System.out.println("bitmap inited");
    offset = overhead - (gap - overhead);

    double threshold = 1.0;
    try {
      while (offset < bitmap.length - gap) {
        // wait for motion
        double acceleration = accelerometer.getAccelY();
        if (acceleration > threshold) {
          while (acceleration > threshold) {
            Thread.sleep(10);
            acceleration = accelerometer.getAccelY();
          }

          bltBitmapForward(bitmap, offset, gap - overhead);

          offset += scrollrate;

        } else if (acceleration < -threshold) {
          while (acceleration < -threshold) {
            Thread.sleep(10);
            acceleration = accelerometer.getAccelY();
          }
          bltBitmapBackward(bitmap, offset, gap - overhead);
          offset += scrollrate;
        }
        try {
          Thread.sleep(100);
        } catch (InterruptedException ex) {
          ex.printStackTrace();
        }
      }
      System.out.println(" finished scrolling " + gap);

    } catch (IOException ex) {
      ex.printStackTrace();
    } catch (InterruptedException ex) {
      ex.printStackTrace();
    }
  }