This is an old revision of the document!


Lahendused harjutustele

Harjutus 2.1
#include <pololu/3pi.h>
 
int main()
{
  delay_ms(3000);
    while(1)
    {
      for(int i = 0; i < 4; i++){
        set_motors(50,50);
        delay_ms(500);
        set_motors(0,50);
        delay_ms(680);
      }
      set_motors(0,0);
      delay_ms(5000);
    }
}
Harjutus 2.2
#include <pololu/3pi.h>
 
int main()
{
	delay_ms(3000);
	while(1)
	{
 
		set_motors(50,50);
		delay_ms(500);
		set_motors(0,50);
		delay_ms(2200);
		set_motors(50,50);
		delay_ms(500);
		set_motors(50,0);
		delay_ms(2200);	
		set_motors(0,0);
		delay_ms(2000);
        }
}
Harjutus 3.1
#include <pololu/3pi.h>
 
int main()
{
	int count;
	while(1)
	{
 
		count = analog_read(TRIMPOT)/128; //ümardub täisarvuks
		clear();
		for(int i = 0; i < count; i++){
		print_character('|');
		}
		lcd_goto_xy(0,1);
		print("C: ");
		print_long(count);
		delay_ms(300);
	}
}
Harjutus 3.2
#include <pololu/3pi.h>
 
int main()
{
	char text[] ="Hello";
	while(1)
	{
 
		for(int i = 4; i >= 0; i--){
			clear();
			for(int j = i; j <= 4; j++){
				print_character(text[j]);
 
			}
			delay_ms(200);
		}
		lcd_scroll(LCD_RIGHT, 8, 250);
	}
}
Harjutus 4.1
#include <pololu/3pi.h>
#include <stdio.h>
 
int main()
{
	lcd_init_printf();
	int count[] = {0, 0, 0};
	unsigned long time;
 
		time = get_ms();
		while(1)
		{
			unsigned char button = get_single_debounced_button_press(ANY_BUTTON);
			if (button & TOP_BUTTON) count[2]++;
			if (button & MIDDLE_BUTTON) count[1]++;
			if (button & BOTTOM_BUTTON) count[0]++;
			if(get_ms() - time > 100){
				 clear();
				 printf("A%2d B%2d\nC%2d", count[0], count[1], count[2]);
				time = get_ms();
			}
		}
}
Harjutus 4.2
#include <pololu/3pi.h>
 
int main()
{
 
		while(1)
		{
			unsigned char button = get_single_debounced_button_press(ANY_BUTTON);
			if (button & TOP_BUTTON) stop_playing();
			if (button & BOTTOM_BUTTON){
				if(!is_playing()) play("!L16 V15 cdefgab>cbagfedcdefgab>cbagfedcdefgab>cbagfedc");
			}
		}
}
et/projects/3pi/solutions.1446725131.txt.gz · Last modified: 2020/07/20 09:00 (external edit)
CC Attribution-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0