NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Project Help and Ideas » Understanding arrays

January 21, 2011
by Jalex
Jalex's Avatar

Hi This is a parcial clip of the keyboad.c program. str_buf[0] = str_buf[1] = 0x00; I don't know what this line does. If I have figured it right we have an array of 21 positions and this would put what is in location 1 in location 0. Why is this done? If it's 0'ing the positions why doesn't is just clear it? Any thing else you think I might not understad is welcome too. So far I have been writing simple things so I am very green at this.

  char str_buf[21];
  uint8_t buf_pos = 0;
  str_buf[0] = str_buf[1] = 0x00;
  while(1) {
    if(char_waiting){
      key_code = read_char();
      if(key_code == 0x5A){ // enter key, clear the line
        buf_pos = 0;
        str_buf[0] = str_buf[1] = 0x00;
      } else if (key_code == 0x66){ //backspace
        buf_pos--;
        str_buf[buf_pos] = 0x00;
      } else {
        str_buf[buf_pos] = render_scan_code(key_code);
        buf_pos++;
        str_buf[buf_pos] = 0x00;
      }
    }

    lcd_home();
    fprintf_P(&lcd_stream,PSTR("%-20s"),str_buf);

    if(shift){
      lcd_line_four();
      fprintf_P(&lcd_stream,PSTR("SHIFT"));
    } else {
      lcd_line_four();
      fprintf_P(&lcd_stream,PSTR("          "));
    }

  }

  return 0;

Post a Reply

Please log in to post a reply.

Did you know that the Timer/Counter modules on the microcontroller can be configured to output a PWM (Pulse Width Modulation) signal? Learn more...