Esempio n. 1
0
void bghighscore_display_line(int8_t rank, int8_t lcd_line) {
    int8_t c;
    lcd_goto_position(lcd_line, 6);
    for (c = 0; c < INITIALS; c++)
        lcd_write_data(highscores[rank].initials[c]);
    lcd_write_byte(' ');
    lcd_write_int16(highscores[rank].score);
}
Esempio n. 2
0
void bggame_over(uint16_t score) {
    // game is over (no more moves)
    nklcd_stop_blinking();
    lcd_clear_and_home();
    lcd_goto_position(0, 6);
    lcd_write_string(PSTR("GAME OVER"));
    lcd_goto_position(2, 4);
    lcd_write_string(PSTR("score: "));
    lcd_write_int16(score);
    nktimer_simple_delay(300);
}
Esempio n. 3
0
void getTemp() {
	uint16_t last_sample = 0;
	double this_temp;
	double temp_avg;
	uint16_t i;
	temp_avg = 0.0;

	for (i=0; i<500; i++) {
		last_sample = adc_read();
		this_temp = sampleToFahrenheit(last_sample);
		temp_avg = temp_avg + this_temp/500.0;
	}

	double c = fahrenheitToCelsius(temp_avg);
	double k = celsiusToKelvin(c);

	// write message to LCD
	lcd_init();
	FILE lcd_stream = FDEV_SETUP_STREAM(lcd_putchar, 0, _FDEV_SETUP_WRITE);
	lcd_home();
	lcd_write_string(PSTR("ADC: "));
	lcd_write_int16(last_sample);
	lcd_write_string(PSTR(" of 1024 "));
	lcd_line_two();

	fprintf_P(&lcd_stream, PSTR("%.2f"), temp_avg);
	lcd_write_data(0xdf);
	lcd_write_string(PSTR("F"));

	lcd_line_three();
	fprintf_P(&lcd_stream, PSTR("%.2f"), c);
	lcd_write_data(0xdf);
	lcd_write_string(PSTR("C"));

	lcd_line_four();
	fprintf_P(&lcd_stream, PSTR("%.2f"), k);
	lcd_write_data(0xdf);
	lcd_write_string(PSTR("K"));
}
Esempio n. 4
0
void poll(){
  // Main polling loop
  
  // Check for a character from the USART
  // See if there is a command comming in
  if (uart_char_is_waiting()) {
    char c = uart_read();
    
    // Update the command state-machine
    if (c == '\n' || c == '\r' ) {
      // End of a command, process it and reset the command string
      if (current_command == COMMAND_NONE) {
      } else if (current_command == COMMAND_INFLATE) {
	syringe_inflate();
	current_state = STATE_INFLATE;
      } else if (current_command == COMMAND_DEFLATE) {
	syringe_deflate();
	current_state = STATE_DEFLATE;
      } else if (current_command == COMMAND_SET_PRESSURE) {
	int ret = sscanf_P(value_str, PSTR("%d"), &target_pressure);
	//	printf_P(PSTR("1 = %d\r\n"), ret );  
	//	printf_P(PSTR("2 = %d\r\n"), target_pressure );
      }
      value_str_i = 0;
      current_command = COMMAND_NONE;
      current_command_state = CMD_STATE_COMMAND;
    } else {
      // In a command string
      if (current_command_state == CMD_STATE_COMMAND) {
	// Command character
	if (c == 'i') {
	  // Inflate
	  current_command = COMMAND_INFLATE;
	} else if (c == 'd') {
	  // Deflate
	  current_command = COMMAND_DEFLATE;
	} else if (c == 'p') {
	  // Set pressure point
	  current_command = COMMAND_SET_PRESSURE;
	} else {
	  current_command = COMMAND_NONE;
	}
	current_command_state = CMD_STATE_EQUAL;
      } else if (current_command_state == CMD_STATE_EQUAL) {
	// Assume the second char is always '='
	current_command_state = CMD_STATE_VALUE;
      } else if (current_command_state == CMD_STATE_VALUE) {
	// In value part of command
	value_str[value_str_i++] = c;
	if (value_str_i >= MAX_VALUE_LENGTH) {
	  value_str_i = MAX_VALUE_LENGTH-1;
	}
	value_str[value_str_i] = 0; // Write NULL terminator
      }
    }
  }
  
  // Check the current pressure
  // take 100 samples and average them!
  // holder variables for temperature data
  uint16_t last_sample = 0;
  double this_temp;
  double pres_avg = 0.0;
  uint8_t i;
  
  for(i=0; i<100; i++) {
    last_sample = adc_read();
    //this_temp = sampleTokPi(last_sample);
    this_temp = last_sample;
    
    // add this contribution to the average
    pres_avg = pres_avg + this_temp/100.0;
  }

  // Check to see if we hit the target presure
  if ( current_state == STATE_INFLATE ) {
    if ( pres_avg >= target_pressure ) {
      // Stop Inflating
      syringe_off();
      current_state = STATE_IDLE;
    }
  } else if ( current_state == STATE_DEFLATE ) {
    if ( pres_avg <= target_pressure ) {
      // Stop Deflating
      syringe_off();
      current_state = STATE_IDLE;      
    }
  }   

  // write message to LCD
  lcd_home();
  lcd_write_string(PSTR("ADC: "));
  lcd_write_int16(last_sample);
  lcd_write_string(PSTR(" of 1024   "));
  lcd_line_two();
  if ( current_state == STATE_IDLE ) {
    fprintf_P(&lcd_stream, PSTR("State: Idle      "));
  } else if ( current_state == STATE_RECV ) {
    fprintf_P(&lcd_stream, PSTR("State: Recv      "));
  } else if ( current_state == STATE_INFLATE ) {
    fprintf_P(&lcd_stream, PSTR("State: Inflate   "));
  } else if ( current_state == STATE_DEFLATE ) {
    fprintf_P(&lcd_stream, PSTR("State: Deflate   "));
  }
  lcd_line_three();
  fprintf_P(&lcd_stream, PSTR("Target Pres: %d"), target_pressure );
  // write message to serial port
  //printf_P(PSTR("%.2f degrees F\r\n"), temp_avg);
  //printf_P(PSTR("Pres = %d\r\n"), target_pressure );
  //printf_P(PSTR("Value = %s\r\n"), value_str );

}