This shows you the differences between two versions of the page.
| et:examples:setup:test [2011/01/31 16:57] – tekitatud raivo.sell | et:examples:setup:test [2020/07/20 12:00] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | <code c> | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | #include " | ||
| + | #include " | ||
| + | |||
| + | #define ULTRASONIC_SPEED_OF_SOUND | ||
| + | |||
| + | |||
| + | |||
| + | ///////////////////////// | ||
| + | |||
| + | int main(void) | ||
| + | { | ||
| + | char adc0[16], | ||
| + | unsigned char new_value=0, | ||
| + | int servopos=1, dcpos=1, | ||
| + | |||
| + | /////////////////////// | ||
| + | |||
| + | // | ||
| + | lcd_gfx_init(); | ||
| + | lcd_gfx_clear(); | ||
| + | adc_init(ADC_REF_AVCC, | ||
| + | segment_display_init(); | ||
| + | pin leds[3] | ||
| + | pin buttons[3] = { PIN(C, 0), PIN(C, 1), PIN(C, 2) }; | ||
| + | pin led_red = PIN(C, 5); | ||
| + | pin sensors = PIN(G, 0); | ||
| + | //pin srf05 = PIN(F,2); | ||
| + | |||
| + | pin_setup_output(sensors); | ||
| + | |||
| + | for (i = 0; i < 3; i++) | ||
| + | { | ||
| + | pin_setup_output(leds[i]); | ||
| + | pin_setup_input(buttons[i]); | ||
| + | dcmotor_init(i); | ||
| + | } | ||
| + | dcmotor_init(3); | ||
| + | encoder_init(0); | ||
| + | encoder_init(1); | ||
| + | /////////////////////////// | ||
| + | while (true) | ||
| + | { | ||
| + | new_value0 = pin_get_value(buttons[0]); | ||
| + | if ((new_value0) && (!old_value0)) | ||
| + | { | ||
| + | //nupp = PINC & 0x07; | ||
| + | nupp++; | ||
| + | if (nupp>4) nupp=0; | ||
| + | pin_toggle(leds[0]); | ||
| + | lcd_gfx_clear(); | ||
| + | } | ||
| + | old_value0 = new_value0; | ||
| + | |||
| + | // | ||
| + | |||
| + | if (nupp==0){ | ||
| + | sprintf(caption0, | ||
| + | sprintf(caption1, | ||
| + | sprintf(adc0, | ||
| + | sprintf(adc1, | ||
| + | sprintf(adc2, | ||
| + | } | ||
| + | ////////////////////////// | ||
| + | |||
| + | else if (nupp==1){ | ||
| + | new_value = pin_get_value(buttons[1]); | ||
| + | if ((new_value) && (!old_value)) | ||
| + | { | ||
| + | // | ||
| + | nupp1=1; | ||
| + | lcd_gfx_clear(); | ||
| + | } | ||
| + | old_value = new_value; | ||
| + | |||
| + | new_value2 = pin_get_value(buttons[2]); | ||
| + | if ((new_value2) && (!old_value2)) | ||
| + | { | ||
| + | // | ||
| + | lcd_gfx_clear(); | ||
| + | nupp1=2; | ||
| + | } | ||
| + | old_value2 = new_value2; | ||
| + | | ||
| + | if (nupp1==1) { | ||
| + | pin_clear(leds[1]); | ||
| + | pin_set(leds[2]); | ||
| + | lcd_taust=1; | ||
| + | sprintf(caption1, | ||
| + | } | ||
| + | else if (nupp1==2) { | ||
| + | pin_set(leds[1]); | ||
| + | pin_clear(leds[2]); | ||
| + | lcd_taust=0; | ||
| + | sprintf(caption1, | ||
| + | } | ||
| + | else { | ||
| + | pin_set(leds[1]); | ||
| + | pin_set(leds[2]); | ||
| + | sprintf(caption1, | ||
| + | nupp1=0; | ||
| + | } | ||
| + | // | ||
| + | | ||
| + | sprintf(adc0, | ||
| + | sprintf(adc1, | ||
| + | sprintf(adc2, | ||
| + | sprintf(caption0, | ||
| + | _delay_ms(100); | ||
| + | } | ||
| + | ////////////////////////// | ||
| + | |||
| + | else if (nupp==2){ | ||
| + | new_value = pin_get_value(buttons[1]); | ||
| + | if ((new_value) && (!old_value)) | ||
| + | { | ||
| + | bit_invert(nupp1, | ||
| + | lcd_gfx_clear(); | ||
| + | } | ||
| + | old_value = new_value; | ||
| + | | ||
| + | if (nupp1) { | ||
| + | pin_clear(sensors); | ||
| + | pin_clear(leds[0]); | ||
| + | sprintf(caption1, | ||
| + | sprintf(adc0, | ||
| + | sprintf(adc1, | ||
| + | sprintf(adc2, | ||
| + | // | ||
| + | } | ||
| + | else { | ||
| + | pin_set(sensors); | ||
| + | pin_set(leds[0]); | ||
| + | sprintf(caption1, | ||
| + | sprintf(adc0, | ||
| + | // | ||
| + | sprintf(adc1, | ||
| + | sprintf(adc2, | ||
| + | } | ||
| + | // | ||
| + | sprintf(caption0, | ||
| + | _delay_ms(500); | ||
| + | } | ||
| + | ///////////////////////// | ||
| + | else if (nupp==3){ | ||
| + | | ||
| + | sprintf(caption0, | ||
| + | sprintf(caption1, | ||
| + | sprintf(adc0, | ||
| + | sprintf(adc1, | ||
| + | sprintf(adc2, | ||
| + | | ||
| + | | ||
| + | | ||
| + | servopos++; | ||
| + | if (servopos> | ||
| + | servopos=-100; | ||
| + | dcpos=dcpos*-1; | ||
| + | pin_toggle(leds[0]); | ||
| + | } | ||
| + | |||
| + | dcmotor_drive(0, | ||
| + | dcmotor_drive(1, | ||
| + | dcmotor_drive(2, | ||
| + | dcmotor_drive(3, | ||
| + | dcpulse=encoder_get_pulses(0); | ||
| + | // | ||
| + | |||
| + | |||
| + | } | ||
| + | ////////////////////////////// | ||
| + | else if (nupp==4){ | ||
| + | sprintf(caption0, | ||
| + | sprintf(caption1, | ||
| + | sprintf(adc0, | ||
| + | sprintf(adc1, | ||
| + | sprintf(adc2, | ||
| + | // | ||
| + | // | ||
| + | } | ||
| + | | ||
| + | else { | ||
| + | pin_toggle(led_red); | ||
| + | _delay_ms(500); | ||
| + | } | ||
| + | //////////////// | ||
| + | |||
| + | // | ||
| + | // | ||
| + | segment_display_write(nupp); | ||
| + | lcd_gfx_backlight(lcd_taust); | ||
| + | lcd_gfx_goto_char_xy(0, | ||
| + | lcd_gfx_write_string(caption0); | ||
| + | lcd_gfx_goto_char_xy(0, | ||
| + | lcd_gfx_write_string(caption1); | ||
| + | lcd_gfx_goto_char_xy(0, | ||
| + | lcd_gfx_write_string(adc0); | ||
| + | lcd_gfx_goto_char_xy(0, | ||
| + | lcd_gfx_write_string(adc1); | ||
| + | lcd_gfx_goto_char_xy(0, | ||
| + | lcd_gfx_write_string(adc2); | ||
| + | | ||
| + | } | ||
| + | } | ||
| + | |||
| + | </ | ||