Ejemplo n.º 1
0
void disp_time(char *timebuf)
{
  static int8_t ppos = 0;
  int8_t pos = 0, ytop=1;
  ht1632_clear();
  ht1632_putchar(0,ytop,timebuf[0]);
  ht1632_putchar(6,ytop,timebuf[1]);
  ht1632_plot(12,ytop+2,1,0);
  ht1632_plot(12,ytop+4,1,0);
  ht1632_putchar(14,ytop,timebuf[2]);
  ht1632_putchar(20,ytop,timebuf[3]);
  ppos = pos;
}
Ejemplo n.º 2
0
void disp_time_seconds(char *timebuf)
{
  static int8_t ppos = 0;
  int8_t pos = 0;
  ht1632_clear();

  // the last arg is 'ramonly' which updates just the shadow_ram
  // Once all the digits are written in ram, we then sync the
  // entire thing in one shot - should be faster.
  ht1632_putchar(0,0,timebuf[0]);
  ht1632_putchar(5,0,timebuf[1]);
  ht1632_putchar(11,0,timebuf[2]);
  ht1632_putchar(16,0,timebuf[3]);
  ht1632_putchar(22,0,timebuf[4]);
  ht1632_putchar(27,0,timebuf[5]);

  pos = seconds%32; 
  ht1632_plotram(pos, 7,1,0);
  ht1632_plotram(ppos,7,0,0);

  ht1632_syncram();
  ppos = pos;
}
Ejemplo n.º 3
0
void ClockController::changeFace(ClockFace* newFace) {
  currentFace = newFace;
  currentFace->init();
  ht1632_clear();
}
Ejemplo n.º 4
0
void mode_draw()
{
  int16_t n;
  uint8_t rc,val;
  uint8_t state = last_button1state; // button push exits this loop
  uint8_t x = 0;
  uint8_t y = 0;
  uint8_t x_mask = ht1632_xmax() - 1;
  uint8_t y_mask = ht1632_ymax() - 1;
  char *ptr;
  char save;

  ht1632_clear();

  // we start the timer when we enter this mode
  start_led_sync_timer();

  // treats each line as a command
  // we only modify the output ram - the timer takes care of the rest
  while(1)
  {
    if(last_button1state !=  state)
      return;
    
    ptr = &BUF[0];
    n = term_recvstr(ptr, BUFSIZE);

    // no data
    if(n == 0) continue;
    // error occured
    if (n < 0) break;

    if(ptr[0]=='q') break;
    if(ptr[0]=='w') 
    {
      ht1632_clearram();
      continue;
    }
    if(ptr[0]=='p')
    {
      // format: p01101 
      //         pxxyy1
      if(n > 5) 
      {
        ptr++; // skip p
        save = *(ptr+2);  
        *(ptr+2) = '\0';
        x = atoi(ptr);

        ptr+=2;
        *ptr = save; 
        save = *(ptr+2);
        *(ptr+2) = '\0';
        y = atoi(ptr);

        ht1632_plotram(x, y, (save=='1')?1:0, 1);
        // format was: p 01 10 1
        // waste of 3 bytes over wireless
        /*
        ptr+=2; *(ptr+2) = '\0';
        x = atoi(ptr);
        ptr+=3; *(ptr+2) = '\0';
        y = atoi(ptr);
        ptr+=3; *(ptr+1) = '\0';
        val = atoi(ptr);
        ht1632_plotram(x, y, val, 1);
        */
      }
      continue;
    }

    ht1632_editram_char(0, 0, ptr, n, 0);

    state = last_button1state;
  }

  stop_led_sync_timer();
}
Ejemplo n.º 5
0
void demo_life()
{
  uint8_t x,y, neighbors, newval;
  int i;
  byte2 xmax = ht1632_xmax();
  byte2 ymax = ht1632_ymax();

  ht1632_clear();

  ht1632_plot(15,9,1,0);  // Plant an "acorn"; a simple pattern that
  ht1632_plot(17,10,1,0); //  grows for quite a while..
  ht1632_plot(14,11,1,0);
  ht1632_plot(15,11,1,0);
  ht1632_plot(18,11,1,0);
  ht1632_plot(19,11,1,0);
  ht1632_plot(20,11,1,0);
  ht1632_plot(seconds%20,10,1,0); // pseudorandom seed
  ht1632_plot(seconds%17,9,1,0); // pseudorandom seed

  if(N_PANELS>1)
  {
    ht1632_plot(seconds%33,11,1,0); 
    ht1632_plot(seconds/2,12,1,0); 
    ht1632_plot((10+seconds)%36,12,1,0); 
    ht1632_plot(34,11,1,0);
    ht1632_plot(35,12,1,0);
    ht1632_plot(36,13,1,0);
    ht1632_plot(37,13,1,0);
    ht1632_plot(38,12,1,0);
    ht1632_plot(39,12,1,0);
    ht1632_plot(40,11,1,0);
    ht1632_plot(seconds%37,13,1,0); 
  }

  _delay_ms(800);   // Play life
  ht1632_snapram();

  // 1000 iterations
  for (i=0; i < 100; i++) {
    for (x=1; x < xmax; x++) {
      for (y=1; y < ymax; y++) {
        neighbors = ht1632_getram(x, y+1) +
          ht1632_getram(x, y-1) +
          ht1632_getram(x+1, y) +
          ht1632_getram(x+1, y+1) +
          ht1632_getram(x+1, y-1) +
          ht1632_getram(x-1, y) +
          ht1632_getram(x-1, y+1) +
          ht1632_getram(x-1, y-1);

        switch (neighbors) {
        case 0:
        case 1:
          newval = 0;   // death by loneliness
          break;
        case 2:         // remains the same
          newval = ht1632_getram(x,y);
          break;  
        case 3:
          newval = 1;   // grow when you have 3 neighbors
          break;
        default:
          newval = 0;   // death by overcrowding
          break;
        }

        ht1632_plot(x,y, newval,0);
      }
    }
    if(last_button1state==0) 
    {
      ht1632_clear();
      return;
    }
    ht1632_snapram();
    _delay_ms(20);
  }
  _delay_ms(1000);
}