Пример #1
0
void rob_lcd_init_printf (void)
{
    vTaskSuspendAll();
    {
        lcd_init_printf();
    }
    xTaskResumeAll();
}
Пример #2
0
int main()
{
	lcd_init_printf();
	clear();	// clear the LCD
	printf("Time: ");
	
	while (1)
	{
		unsigned char button = get_single_debounced_button_press(ANY_BUTTON);
		switch (button)
		{
			case BUTTON_A:
				play_note(A(4), 50, 10);
				break;
			case BUTTON_B:
				play_note(B(4), 50, 10);
				break;
			case BUTTON_C:
				play_note(C(5), 50, 10);
		}

		button = get_single_debounced_button_release(ANY_BUTTON);
		switch (button)
		{
			case BUTTON_A:
				play_note(A(5), 50, 10);
				break;
			case BUTTON_B:
				play_note(B(5), 50, 10);
				break;
			case BUTTON_C:
				play_note(C(6), 50, 10);
		}

		unsigned long ms = get_ms();	// get elapsed milliseconds
		// convert to the current time in minutes, seconds, and hundredths of seconds
		unsigned char centiseconds = (ms / 10) % 100;
		unsigned char seconds = (ms / 1000) % 60;
		unsigned char minutes = (ms / 60000) % 60;

		lcd_goto_xy(0, 1);				// go to the start of the second LCD row
		// print as [m]m:ss.cc (m = minute, s = second, c = hundredth of second)
		printf("%2u:%02u.%02u", minutes, seconds, centiseconds);
	}

}
Пример #3
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
	}
}
Пример #4
0
int main()
{
  lcd_init_printf();
  clear();
  lcd_goto_xy(0,0);
  printf("Calculating...");

  volatile int i,j;

  // Measure time for loop execution (without test code)
  long iteration = 10000;
  long test_iteration = 1000;

  //TODO: possible only call ticks_to_microseceonds once after all times are recorded.
  //time to loop million times
  long time1 = get_ticks();
  for (i=0; i < iteration; i++);
  long time2 = get_ticks();
  long loop1time = time2 - time1;

  long time3 = get_ticks();
  for (i=0; i < iteration; i++) {
    for(j=0;j<test_iteration;j++);
  }
  long time4 = get_ticks();
  long loop2time = time4 - time3;

  //calculate time to loop 1000 times in microseconds
  //result is about .924 ms
  //so 1082 iterations take 1 ms
  //for some reason this is actually 2 ms, so divide by 2
  long wcet = ticks_to_microseconds(loop2time - loop1time)/iteration;
  long one_ms = (1000*test_iteration)/(wcet*2); 

  clear();
  lcd_goto_xy(0,0);
  printf("time:%li",wcet);
  lcd_goto_xy(0,1);
  printf("1 ms iter:%li",one_ms);
}
Пример #5
0
int main()
{
	delay_ms(500); // warming up

	lcd_init_printf();

	printf("\nAssert");
	assert(1 == 1); // make sure assert works

	test_qtr();
	test_pushbuttons();
	test_buzzer();
	test_motors();
	test_lcd();
	test_leds();
	test_analog();
	test_delay();

	clear();
	printf("\nSuccess");
	play("O5 c16");
	
	while(1);
}
Пример #6
0
/*==========la fonction main()=======*/
int main(void) {

    lcd_init_printf();
    pololu_3pi_init(2000);  
    play_mode(PLAY_CHECK);
    clear();
    print("Hello!");
    play("L16 ceg>c");
    // start receiving data at 9600 baud
    serial_set_baud_rate(9600);
    serial_receive_ring(buffer, 100);
      
    int i=0;
    char dirct,chaine[4], comp='C',*recuper = NULL, *ok;
    long val, veri=0;
    char command;
	/* la boucle qui permet de recuperer la trame caractere par caractere */
    while(1){
	
        for(i=0;i<4;i++){
            command = read_next_byte();
            if (command)
            {
                chaine[i] = command;
            }
        }
         /*recuperation de la lettre recu dans la trame */ 
        dirct = chaine[0];
        
        /*recuperation du reste de la trame en chaine de caractere */
        recuper = strchr(chaine,chaine[1]);
        
        /*conversion de cette chaine recuperer en entier (type long)*/
        val = strtol(recuper, &ok,10);
        
	    /* cette condition permet d'eviter l'execution de la meme trame plusieurs fois*/        
        if(dirct != comp || veri != val)
        {
        clear();
        printf("%s",chaine);
        switch(dirct)
        {
            case 'A':
                avancer(val);
                break;
            case 'R':
                reculer(val);
                break;
            case 'D':
                droit(val);
                break;
            case 'G':
                gauche(val);
                break;
            case 'M':
                melodie();
                break;
            default:
                set_motors(0,0);
                break;
            }
            comp = dirct;
            veri = val;
        }
    }
return 0;
}
int main(void) {
	
	delay_ms(100);
	
	init_leds();
	init_timers();
	init_motors();

	// Used to print to serial comm window
	char tempBuffer[80];
	
	// Initialization here.
	lcd_init_printf();	// required if we want to use printf() for LCD printing
	init_menu();	// this is initialization of serial comm through USB
	
	clear();	// clear the LCD

	//enable interrupts
	sei();
	
	while (1) {

		process_Trajectory();

		if (updateLCD)
		{
			//first line
			lcd_goto_xy(8,0);
			print("        ");
			
			lcd_goto_xy(8,0);
			//print_long(global_counts_m1);
			sprintf( tempBuffer, "V=%d\r", voltage);
			print(tempBuffer);

			//next line
			lcd_goto_xy(0,1);
			sprintf( tempBuffer, "R=%3.2f RPM=%3.2f\r", rotations, RPM);
			print(tempBuffer);
			
			updateLCD = false;
		}
		if (display_values_flag)
		{
			if (TARGET_ROT)
				length = sprintf( tempBuffer, "Kp:%f Ki:%f Kd:%f Pr:%f Pm:%f T:%d\r\n", Kp, Ki, Kd, goal, rotations, voltage);
			else if (TARGET_RPM)
				length = sprintf( tempBuffer, "Kp:%f Ki:%f Kd:%f Pr:%f Pm:%f T:%d\r\n", Kp, Ki, Kd, goal, RPM, voltage);
			else 
				length = sprintf( tempBuffer, "Kp:%f Ki:%f Kd:%f Pr:%f Pm:NA T:%d\r\n", Kp, Ki, Kd, goal, voltage);
			
			print_usb( tempBuffer, length );
			
			length = sprintf( tempBuffer, "C0:%d C1:%d C2:%d C3:%d C4:%d C5:%d Man:%d Eq:%d\r\n",	command_list[0], 
																						command_list[1],
																						command_list[2],
																						command_list[3],
																						command_list[4],
																						command_list[5],
																						maneuver_complete,
																						equilibrium);
			print_usb( tempBuffer, length );
							
			length = sprintf( tempBuffer, "%f, %f, %f\r\n",	error, integral, derivative);
			print_usb( tempBuffer, length );
			
			display_values_flag = false;
		}
		if (ready_to_dump_log)
		{
			ready_to_dump_log = false;
			
			length = sprintf( tempBuffer, "Goal, Kp, Ki, Kd, Rot, RPM, Volt\r\n");
			print_usb( tempBuffer, length );
			length = sprintf( tempBuffer, "%f, %f, %f, %f, %f, %f, %d\r\n", goal, Kp, Ki, Kd, rotations, RPM, voltage);
			print_usb( tempBuffer, length );
			
			int delta = (log_stop_timestep-log_start_timestep);
			
			length = sprintf( tempBuffer, "Time, Error, KpError, KiIntegral, KdDerivative, Rotations, RPM, Voltage\r\n");
			print_usb( tempBuffer, length );
			
			float temp_Kp = (Kp == 0.0) ? 1.0 : Kp;
			float temp_Ki = (Ki == 0.0) ? 1.0 : Ki;
			float temp_Kd = (Kd == 0.0) ? 1.0 : Kd;
			
			float time;
			
			for(int i=0; i<delta; i++)
			{
				time = (float)((i*dt)*60);
				length = sprintf( tempBuffer, "%f %f %f %f %f %f %f %d\r\n", time,	//time expressed in seconds
																			LOG[i].error,
																			(float)(temp_Kp * LOG[i].error),
																			(float)(temp_Ki * LOG[i].integral),
																			(float)(temp_Kd * LOG[i].derivative),
																			LOG[i].rotations,
																			LOG[i].RPM,
																			LOG[i].voltage);
				print_usb( tempBuffer, length );	
			}
		}

		//Process Control from the USB Port
		serial_check();
		check_for_new_bytes_received();
					
	} //end while loop
} //end main