int main() { TCCR0A = 0; // configure timer0 to run at 78 kHz TCCR0B = 0x04; // and overflow when TCNT0 = 256 (~3 ms) play_from_program_space(rhapsody); while(1) { // allow the sequence to keep playing automatically through the following delays #ifndef ALWAYS_CHECK play_mode(PLAY_AUTOMATIC); #else play_mode(PLAY_CHECK); #endif lcd_goto_xy(0, 0); print("blink!"); int i; for (i = 0; i < 8; i++) { #ifdef ALWAYS_CHECK play_check(); #endif red_led(1); delay_ms(500); red_led(0); delay_ms(500); } lcd_goto_xy(0, 0); print("timing"); lcd_goto_xy(0, 1); print(" "); // clear bottom LCD line // turn off automatic playing so that our time-critical code won't be interrupted by // the buzzer's long timer1 interrupt. Otherwise, this interrupt could throw off our // timing measurements. Instead, we will now use playCheck() to keep the sequence // playing in a way that won't throw off our measurements. #ifndef ALWAYS_AUTOMATIC play_mode(PLAY_CHECK); #endif unsigned char maxTime = 0; for (i = 0; i < 8000; i++) { TCNT0 = 0; while (TCNT0 < 20) // time for ~250 us ; if (TCNT0 > maxTime) maxTime = TCNT0; // if the elapsed time is greater than the previous max, save it #ifndef ALWAYS_AUTOMATIC play_check(); // check if it's time to play the next note and play it if so #endif } lcd_goto_xy(0, 1); print("max="); print_long((unsigned int)maxTime); print(" "); // overwrite any left over characters } }
/*==========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() { pololu_3pi_init(2000); play_mode(PLAY_CHECK); clear(); // start receiving data at 115.2 kbaud serial_set_baud_rate(115200); serial_receive_ring(buffer, 100); while(1) { // wait for a command char command = read_next_byte(); // The list of commands is below: add your own simply by // choosing a command byte and introducing another case // statement. switch(command) { case (char)0x00: // silent error - probable master resetting break; case (char)0x81: send_signature(); break; case (char)0x86: send_raw_sensor_values(); break; case (char)0x87: send_calibrated_sensor_values(1); break; case (char)0xB0: send_trimpot(); break; case (char)0xB1: send_battery_millivolts(); break; case (char)0xB3: do_play(); break; case (char)0xB4: calibrate_line_sensors(IR_EMITTERS_ON); send_calibrated_sensor_values(1); break; case (char)0xB5: line_sensors_reset_calibration(); break; case (char)0xB6: send_line_position(); break; case (char)0xB7: do_clear(); break; case (char)0xB8: do_print(); break; case (char)0xB9: do_lcd_goto_xy(); break; case (char)0xBA: auto_calibrate(); break; case (char)0xBB: set_pid(); break; case (char)0xBC: stop_pid(); break; case (char)0xC1: m1_forward(); break; case (char)0xC2: m1_backward(); break; case (char)0xC5: m2_forward(); break; case (char)0xC6: m2_backward(); break; default: clear(); print("Bad cmd"); lcd_goto_xy(0,1); print_hex_byte(command); play("o7l16crc"); continue; // bad command } } }