Ejemplo n.º 1
0
void test()
{
	unsigned char button;

	clear();
	delay(200);
	print("Orangutn");	// print to the top line of the LCD
	delay_ms(400);		// delay 200 ms
	lcd_goto_xy(0, 1);	// go to the start of the second LCD line

#if defined __AVR_ATmega328P__
	print(" SV-328");	// print to the bottom line of the LCD
#elif defined __AVR_ATmega168__
	print(" SV-168");	// print to the bottom line of the LCD
#else
#error "Unrecognized device type"
#endif

	delay_ms(1000);		// delay 700 ms

	clear();			// clear the LCD, move cursor to start of top line

	print("  VBAT");

	do
	{
		// Perform 10-bit analog-to-digital conversions on ADC channel 6.
		// Average ten readings and return the result, which will be one
		// third of the battery voltage when the "ADC6 = VBAT/3" solder
		// bridge is in place on the bottom of the Orangutan PCB
		int vbat = analog_read_average(6, 10);	// 10-sample avg of ADC6
		vbat = to_millivolts(vbat) * 3;	// convert reading to bat. voltage (mV)
		lcd_goto_xy(0, 1);	// go to the start of the second LCD line
		print_long(vbat);	// display battery voltage in millivolts
		print(" mV ");		// display the units
		delay_ms(50);		// delay for 50 ms
		button = button_is_pressed(ANY_BUTTON);	// check for button press
	}
	while (button == 0);	// loop if no buttons are being pressed


	// *** MAIN LOOP ***

	while (1)	// loop forever
	{
		if (button & TOP_BUTTON)			// if the top button is pressed
			button = melodyTest();	// this func. loops until next button press

		else if (button & MIDDLE_BUTTON)	// if the middle button is pressed
			button = IOTest();		// this func. loops until next button press

		else if (button & BOTTOM_BUTTON)	// if the bottom button is pressed
			button = motorTest();	// this func. loops until next button press
	}
}
Ejemplo n.º 2
0
int main()
{
	lcd_init_printf();	// required if we want to use printf()

	clear();			// clear the LCD
	delay_ms(200);		// wait for 200 ms

	printf("hello");	// print "hello" on the first line of the LCD
	delay_ms(200);		// wait for 200 ms
	printf("\nworld");	// print "world" on the second line (because of '\n')
	delay_ms(2000);		// wait for 2 seconds

	clear();			// clear the LCD

	unsigned char ch;
	for (ch = 'A'; ch <= 'z'; ch++)	// demonstrate LCD wrapping
	{
		printf("%c", ch);	// print a string of characters that wraps when
		delay_ms(50);		// it reaches the end of the LCD
	}
	delay_ms(2000);		// wait for 2 seconds

	clear();			// clear the LCD

	int i;
	printf("Hex Dec");
	for(i = 0; i <= 500; i += 50)	// demonstrate LCD scrolling
	{
		delay_ms(800 - i);	// the delay gets shorter as i gets bigger
		printf("\n%03X %3d", i, i);	// print i as 3-digit, zero-padded hex
									// and a space-padded 3-digit decimal
	}
	delay_ms(2000);		// wait for 2 seconds

	clear();			// clear the LCD
	printf("Trimpot:");

	while (1)			// continuously display the trimpot voltage in mV
	{
		lcd_goto_xy(0, 1);	// go to start of second LCD row
		printf("%4u mV", to_millivolts(read_trimpot()));	// print trimpot voltage
		delay_ms(50);	// wait for 50 ms to reduce LCD flicker
	}
}
Ejemplo n.º 3
0
int main()
{
  set_analog_mode(MODE_10_BIT); // 10-bit analog-to-digital conversions

  while(1)                      // run over and over again
  {
    lcd_goto_xy(0,0);           // LCD cursor to home position (upper-left)
    print_long(to_millivolts(read_trimpot()));  // trimpot output in mV
    print(" mV  ");             // added spaces are to overwrite left over chars

    lcd_goto_xy(0, 1);          // LCD cursor to start of the second line

    unsigned int temp = read_temperature_f();  // get temp in tenths of a degree F
    print_long(temp/10);             // get the whole number of degrees
    print_character('.');            // print the decimal point
    print_long(temp - (temp/10)*10); // print the tenths digit
    print_character(223);       // print a degree symbol
    print("F  ");               // added spaces are to overwrite left over chars

    delay_ms(100);              // wait for 100 ms (otherwise LCD flickers too much)
  } 
}
Ejemplo n.º 4
0
void test_analog()
{
  // test that set/get mode works
  set_analog_mode(MODE_8_BIT);
  printf("\nGet8BIT");
  assert(MODE_8_BIT == get_analog_mode());

  set_analog_mode(MODE_10_BIT);
  printf("\nGet10BIT");
  assert(MODE_10_BIT == get_analog_mode());

  // read the trimpot in 10 bit mode and compare it to 8 bit mode
  int x1 = analog_read(7);

  set_analog_mode(MODE_8_BIT);
  delay_ms(1); // required for readings to stabilize

  int x2 = analog_read(7);

  printf("\n8BIT10BIT %d %d",x1,x2);
  assert( abs((x1>>2) - x2) < 10 );

  // make sure that the average reading is more stable than individual readings
  set_analog_mode(MODE_10_BIT);
  unsigned char i;
  int min = 1023, max = 0, avg_min = 1023, avg_max = 0;
  
  for(i=0;i<10;i++)
  {
    int x1 = analog_read(7);
    int x2 = analog_read_average(7,256);

    if(x1 > max) max = x1;
    if(x1 < min) min = x1;

    if(x2 > avg_max) avg_max = x2;
    if(x2 < avg_min) avg_min = x2;

    printf("\nAvgComp %03x %03x", x1, x2);
    assert( abs(x1-x2) < 10);
  }

  printf("\nAB%03x%03x%03x%03x",max,min,avg_max,avg_min);
  assert( max - min >= avg_max - avg_min);

  // check that temp C and F return appropriate values in 10bit mode
  set_analog_mode(MODE_10_BIT);
  x1 = analog_read_average(6,100);

  int expect_temp_f = (((int)(analog_read_average_millivolts(TEMP_SENSOR, 20)) * 12) - 634) / 13;
  int expect_temp_c = (((int)(analog_read_average_millivolts(TEMP_SENSOR, 20) * 20)) - 7982) / 39;
  int temp_f = read_temperature_f();
  int temp_c = read_temperature_c();

  printf("\nTF10 %d %d", expect_temp_f, temp_f);
  assert( expect_temp_f/5 == temp_f/5 );

  printf("\nTC10 %d %d", expect_temp_c, temp_c);
  assert( expect_temp_c/5 == temp_c/5 );

  // try temp in 8bit mode
  set_analog_mode(MODE_8_BIT);
  delay_ms(1); // required for readings to stabilize?
  temp_f = read_temperature_f();
  temp_c = read_temperature_c();

  printf("\nTF8 %d %d", expect_temp_f, temp_f);
  assert( (expect_temp_f - temp_f) <= 20 );

  printf("\nTC8 %d %d", expect_temp_c, temp_c);
  assert( abs(expect_temp_c - temp_c) <= 20 );

  // test background conversion
  set_analog_mode(MODE_10_BIT);
  delay_ms(1); // required for readings to stabilize
  x1 = analog_read_average(6,100);
  
  start_analog_conversion(6);

  while(analog_is_converting())
    printf("\nConvert");
  
  x2 = analog_conversion_result();
  printf("%d %d", x1, x2);
  assert( abs(x1 - x2) < 10 );

  // make sure to_millivolts works in 8 and 10 bit mode
  set_analog_mode(MODE_10_BIT);

  x1 = 5000;
  x2 = to_millivolts(1023);
  printf("\nmV1 %d %d",x1,x2);
  assert( x1 == x2 );

  x1 = 2498;
  x2 = to_millivolts(511);
  printf("\nmV2 %d %d",x1,x2);
  assert( x1 == x2 );

  x1 = 0;
  x2 = to_millivolts(0);
  printf("\nmV3 %d %d",x1,x2);
  assert( x1 == x2 );

  set_analog_mode(MODE_8_BIT);

  x1 = 5000;
  x2 = to_millivolts(255);
  printf("\nmV4 %d %d",x1,x2);
  assert( x1 == x2 );

  x1 = 2490;
  x2 = to_millivolts(127);
  printf("\nmV5 %d %d",x1,x2);
  assert( x1 == x2 );

  x1 = 0;
  x2 = to_millivolts(0);
  printf("\nmV6 %d %d",x1,x2);
  assert( x1 == x2 );
}