// process_received_byte: Responds to a byte that has been received on // USB_COMM. If you are writing your own serial program, you can // replace all the code in this function with your own custom behaviors. void process_received_byte(char byte) { clear(); // clear LCD print("RX: "); print_character(byte); lcd_goto_xy(0, 1); // go to start of second LCD row switch(byte) { // If the character 'G' or 'g' is received, toggle the green LED. case 'G': case 'g': green_led(TOGGLE); print("green LED"); break; // If the character 'R' or 'r' is received, toggle the red LED. case 'R': case 'r': red_led(TOGGLE); print("red LED"); break; // If the character 'C' or 'c' is received, play the note C. case 'C': case 'c': play_from_program_space(PSTR("c16")); print("play note C"); break; // If the character 'D' or 'd' is received, play the note D. case 'D': case 'd': play_from_program_space(PSTR("d16")); print("play note D"); break; // If any other character is received, change its capitalization and // send it back. default: wait_for_sending_to_finish(); send_buffer[0] = byte ^ 0x20; serial_send(USB_COMM, send_buffer, 1); print("TX: "); print_character(send_buffer[0]); break; } }
void ir_test() { unsigned int sensors[5]; // an array to hold sensor values if(button_is_pressed(BUTTON_C)) read_line_sensors(sensors, IR_EMITTERS_OFF); else read_line_sensors(sensors,IR_EMITTERS_ON); unsigned char i; for(i=0; i<5; i++) { // Initialize the array of characters that we will use for the // graph. Using the space, an extra copy of the one-bar // character, and character 255 (a full black box), we get 10 // characters in the array. // The variable c will have values from 0 to 9, since // values are in the range of 0 to 2000, and 2000/201 is 9 // with integer math. char c = bar_graph_characters[sensors[i]/201]; // Display the bar graph characters. print_character(c); } // Display an indicator of whether IR is on or off if(button_is_pressed(BUTTON_C)) print("IR-"); else print(" C"); delay_ms(100); }
void print_object (STREAM stream, D instance, BOOL escape_p, int print_depth) { enum dylan_type_enum type = dylan_type(instance); switch (type) { case integer_type: print_integer(stream, instance, escape_p, print_depth); break; case character_type: print_character(stream, instance, escape_p, print_depth); break; case float_type: print_float (stream, instance, escape_p, print_depth); break; case dylan_boolean_type: print_boolean(stream, instance, escape_p, print_depth); break; case string_type: print_string (stream, instance, escape_p, print_depth); break; case vector_type: print_vector(stream, instance, escape_p, print_depth); break; case pair_type: print_pair(stream, instance, escape_p, print_depth); break; case empty_list_type: print_empty_list(stream, instance, escape_p, print_depth); break; case symbol_type: print_symbol(stream, instance, escape_p, print_depth); break; case simple_condition_type: print_simple_condition(stream, instance, escape_p, print_depth); break; case class_type: print_class(stream, instance, escape_p, print_depth); break; case function_type: print_function(stream, instance, escape_p, print_depth); break; case unknown_type: format(stream, "?%lx", instance); break; default: print_user_defined(stream, instance, escape_p, print_depth); break; } }
void music_test() { static char fugue_title_pos = 0; static long last_shift = 0; char c,i; if(get_ms() - last_shift > 250) { for(i=0; i<8; i++) { c = pgm_read_byte(fugue_title + fugue_title_pos + i); print_character(c); } last_shift = get_ms(); fugue_title_pos ++; if(fugue_title_pos + 8 >= sizeof(fugue_title)) fugue_title_pos = 0; } if(!is_playing()) { play_from_program_space(fugue); } delay_ms(100); }
int main() { lcd_load_custom_character(happy, 0); lcd_load_custom_character(sad, 1); lcd_load_custom_character(indifferent, 2); lcd_load_custom_character(surprised, 3); lcd_load_custom_character(mocking, 4); clear(); // this must be called before we can use the custom characters print("mood: ?"); // initialize the random number generator based on how long we hold the button the first time wait_for_button_press(ANY_BUTTON); long seed = 0; while(button_is_pressed(ANY_BUTTON)) seed++; srandom(seed); while(1) { lcd_goto_xy(6, 0); // move cursor to the correct position char mood; do { mood = random()%5; } while (mood == prevMood); // ensure we get a new mood that differs from the previous prevMood = mood; print_character(mood); // print a random mood character wait_for_button(ANY_BUTTON); // wait for any button to be pressed } }
int main() { print_character('c'); print_int(10); print_string("Ahoj!"); return 0; }
void rob_print_character (char c) { vTaskSuspendAll(); { print_character (c); moveCursorOn (1); } xTaskResumeAll(); }
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(" LV-328"); // print to the bottom line of the LCD #elif defined __AVR_ATmega168__ print(" LV-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(" Temp."); 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 Tf = read_temperature_f(); // read temp sensor on ADC6 in 0.1°F lcd_goto_xy(1, 1); // second character of the second LCD line print_long(Tf/10); // display temperature in °F print("."); // print the decimal point print_long(Tf - 10*(Tf/10)); // display the tenths digit print_character(223); // display the degree symbol character (°) print("F "); // display the units delay_ms(50); // delay for 50 ms button = button_is_pressed(ALL_BUTTONS); // 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 } }
auto parse(T&& x) { switch(current_mode) { default: throw std::runtime_error("Error: Invalid sound engine mode."); break; case mode::SOUND: play_sound(std::forward<T>(x)); break; case mode::PRINT: print_character(std::forward<T>(x)); break; case mode::VOLUME: set_volume(std::forward<T>(x)); break; case mode::DURATION: set_duration(std::forward<T>(x)); break; } }
/** display_readings **************************************** * displays the sensor readings using a bar graph * * @params calibrated_values -- array of 5 sensor readings @pre [0,1000] */ void display_readings(const unsigned int calibrated_values[]) { const char display_characters[10] = {' ',0,0,1,2,3,4,5,6,255}; lcd_goto_xy(0,1); for (int s = 0; s < 5; s++) { int scaled_value = calibrated_values[s]/101; print_character(display_characters[scaled_value]); } }
void input_character(char insert_key, int x) { int Cnt = 1; CTAG *fallow; CTAG *current; CTAG *newnode; newnode = (CTAG *) malloc (sizeof(CTAG)); if(NULL == head) { head = newnode; newnode->next = NULL; newnode->prev = NULL; newnode->character = insert_key; newnode->cNum = 1; now_cur = newnode; move_cursor(0, x, 4); print_character(x, 4, insert_key, 7); } else { fallow = now_cur; current = now_cur->next; Cnt++; if(current == NULL) { newnode->prev = fallow; fallow->next = newnode; now_cur = newnode; newnode->character = insert_key; newnode->cNum = Cnt; move_cursor(0, x, 4); print_character(x, 4, insert_key, 7); } } return ; }
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) } }
void display_values(unsigned int *values, unsigned int max) { unsigned char i; unsigned char characters[] = {' ',0,1,2,3,4,5,255}; lcd_goto_xy(0,1); for(i=0;i<5;i++) { // get characters[0] to characters[7] print_character(characters[values[i]*8/(max+1)]); } }
/****************** Main ******************************************************/ int main(const int argc, const char **argv) { print_character('*',60); const time_t start = time(NULL); em1d f(argc,argv); /*************************************************************************/ for(int n=1; n <= f.nsteps; n++) f.advance_a_step(n); /*************************************************************************/ ShowRunTime(start,time(NULL)); return EXIT_SUCCESS; }
void display_values(unsigned int *values, unsigned int max) { unsigned char i; unsigned char characters[] = {' ',0,1,2,3,4,5,255}; lcd_goto_xy(0,1); for(i=0;i<5;i++) { // get characters[0] to characters[7] //print_character('0'+values[i] * 10 /(max+1)); // for deugging, shows percentage instead of graph print_character(characters[values[i]*8/(max+1)]); } }
const char * kprint(const char *s) { char *res; int n; if (s != NIL) { do { *res++ = *s; print_character(*s++); } while (n++ && (*res++ = *s) != '\0'); return res-n; } else { return NIL; } }
int main(void) { lcd_load_custom_character(smile, 0); clear(); while (1) { for (this_row = 0; this_row <= 1; this_row++) { <#statements#> } for (i = 0; i <= 7; i += 2) { char output = 0; lcd_goto_xy(i, 0); print_character(output); delay_ms(500); } } return 0; /* never reached */ }
static void cut_mark_point(char out, char *filename, int lineNumber ) { if ((count % 10) == 0) { if ((count % 50) == 0) new_line(); print_integer_in_field( count, 5 ); } print_character(out); count++; if( count == breakpoint ) { print_string_as_error( filename, lineNumber, "Breakpoint hit" ); new_line(); cut_exit(); } }
int printf_loop(const char *fmt, char **str, va_list *list) { int l; l = 0; while (*fmt != 0) { if (*fmt == '%' && *(fmt + 1) != '%') recup_arg(&fmt, list, str, &l); else if (*fmt == '%' && *(fmt + 1) == '%') print_pourcent(&fmt, str, &l); else if (*fmt == '{') make_color(&fmt, str, &l); else print_character(&fmt, str, &l); } return (l); }
void display_levels(unsigned int *sensors) { clear(); int i; for(i=0;i<5;i++) { // Initialize the array of characters that we will use for the // graph. Using the space, an extra copy of the one-bar // character, and character 255 (a full black box), we get 10 // characters in the array. // The variable c will have values from 0 to 9, since // values are in the range of 0 to 1000, and 1000/101 is 9 // with integer math. char c = bar_graph_characters[sensors[i]/101]; // Display the bar graph characters. print_character(c); } }
// Displays data to the screen void do_print() { unsigned char string_length = read_next_byte(); if(check_data_byte(string_length)) return; unsigned char i; for(i=0;i<string_length;i++) { unsigned char character; character = read_next_byte(); if(check_data_byte(character)) return; print_character(character); } }
void display_readings(const unsigned int *calibrated_values) { unsigned char i; for(i=0;i<5;i++) { // Initialize the array of characters that we will use for the // graph. Using the space, an extra copy of the one-bar // character, and character 255 (a full black box), we get 10 // characters in the array. const char display_characters[10] = {' ',0,0,1,2,3,4,5,6,255}; // The variable c will have values from 0 to 9, since // calibrated values are in the range of 0 to 1000, and // 1000/101 is 9 with integer math. char c = display_characters[calibrated_values[i]/101]; // Display the bar graph character. print_character(c); } }
void print_number(uint32_t number, uint32_t x, uint32_t y, volatile unsigned char *fb, uint32_t offset) { uint8_t non_zero_met = 0; uint32_t division; uint32_t current; for (int i = 10; i >= 0; --i) { current = power(10, i); division = number / current; number = number % current; if (division != 0) { non_zero_met = 1; } if (i == 1) { non_zero_met = 1; } if (non_zero_met) { print_character(&char_sprite_array[division * 64], x + 80 - (8 * i), y + offset, fb); } } }
/** * Print user input prompt. */ void TextMan::write_prompt() { int l, fg, bg, pos; if (!game.input_enabled || game.input_mode != INPUT_NORMAL) return; l = game.line_user_input; fg = game.color_fg; bg = game.color_bg; pos = game.cursor_pos; debugC(4, kDebugLevelText, "erase line %d", l); clear_lines(l, l, game.color_bg); debugC(4, kDebugLevelText, "prompt = '%s'", agi_sprintf(game.strings[0])); print_text(game.strings[0], 0, 0, l, 1, fg, bg); print_text((char *)game.input_buffer, 0, 1, l, pos + 1, fg, bg); print_character(pos + 1, l, game.cursor_char, fg, bg); flush_lines(l, l); do_update(); }
static void space( void ) { print_character( ' ' ); }
static void dot( void ) { print_character( '.' ); }
void test_qtr() { unsigned int values[5]; clear(); // Wait for each sensor to be > 750 while the others are < 250. unsigned int passed_sensors[5] = {0,0,0,0,0}; while(!button_is_pressed(BUTTON_B)) { read_line_sensors(values,IR_EMITTERS_ON); unsigned char i; unsigned char sensor_above=0; char num_above=0; char num_below=0; for(i=0;i<5;i++) { if(values[i] > 750) { sensor_above = i; num_above ++; } else if(values[i] < 500) num_below ++; } if(num_above == 1 && num_below == 4) passed_sensors[sensor_above] = 1; lcd_goto_xy(0,0); for(i=0;i<5;i++) { if(passed_sensors[i]) print_character('*'); else print_character(' '); } display_values(values,1000); lcd_goto_xy(6,1); print("B"); delay_ms(50); } while(button_is_pressed(ALL_BUTTONS)); clear(); // off values while(!button_is_pressed(BUTTON_C)) { read_line_sensors(values,IR_EMITTERS_OFF); lcd_goto_xy(0,0); print("IR- "); display_values(values,1000); lcd_goto_xy(6,1); print("C"); delay_ms(50); } while(button_is_pressed(ALL_BUTTONS)); }
auto play_sound(T&& x) { print_character(x); Beep(frequency(x), duration); }
//--------------------------------------------------------------------------------------- // If there are received bytes to process, this function loops through the receive_buffer // accumulating new bytes (keystrokes) in another buffer for processing. void check_for_new_bytes_received() { /* The receive_buffer is a ring buffer. The call to serial_check() (you should call prior to this function) fills the buffer. serial_get_received_bytes is an array index that marks where in the buffer the most current received character resides. receive_buffer_position is an array index that marks where in the buffer the most current PROCESSED character resides. Both of these are incremented % (size-of-buffer) to move through the buffer, and once the end is reached, to start back at the beginning. This process and data structures are from the Pololu library. See examples/serial2/test.c and src/OrangutanSerial/ * A carriage return from your comm window initiates the transfer of your keystrokes. All key strokes prior to the carriage return will be processed with a single call to this function (with multiple passes through this loop). On the next function call, the carriage return is processes with a single pass through the loop. The menuBuffer is used to hold all keystrokes prior to the carriage return. The "received" variable, which indexes menuBuffer, is reset to 0 after each carriage return. */ char menuBuffer[32]; static int received = 0; int evaluate = 0; // while there are unprocessed keystrokes in the receive_buffer, grab them and buffer // them into the menuBuffer while(serial_get_received_bytes(USB_COMM) != receive_buffer_position) { // place in a buffer for processing menuBuffer[received] = receive_buffer[receive_buffer_position]; print_usb_char( menuBuffer[received] ); #ifdef ECHO2LCD lcd_goto_xy(0,0); print("RX: ("); print_long(menuBuffer[received]); print_character(')'); for (int i=0; i<received; i++) { print_character(menuBuffer[i]); } #endif if ( menuBuffer[received] == '\r' ) { print_usb( "\n" ); evaluate = 1; } ++received; // Increment receive_buffer_position, but wrap around when it gets to // the end of the buffer. if ( receive_buffer_position == sizeof(receive_buffer) - 1 ) { receive_buffer_position = 0; } else { receive_buffer_position++; } } #ifdef ECHO2LCD lcd_goto_xy(0,1); print("RX: ("); print_long(received); print_character(')'); for (int i=0; i<received; i++) { print_character(menuBuffer[i]); } #endif // If there were keystrokes processed, check if a menu command if ( evaluate ) {/* // if only 1 received, it was MOST LIKELY a carriage return. // Even if it was a single keystroke, it is not a menu command, so ignore it. if ( 1 == received ) { received = 0; return; }*/ // Process buffer: terminate string, process, reset index to beginning of array to receive another command menuBuffer[received] = '\0'; #ifdef ECHO2LCD lcd_goto_xy(0,1); print("RX: ("); print_long(received); print_character(')'); for (int i=0; i<received; i++) { print_character(menuBuffer[i]); } #endif process_received_string(menuBuffer); received = 0; } }
void motor_test() { static char m1_back = 0, m2_back = 0; char m1_char, m2_char; if(button_is_pressed(BUTTON_A)) { if(m1_speed == 0) { delay_ms(200); // If the button is pressed quickly when the motor is off, // reverse direction. if(!button_is_pressed(BUTTON_A)) m1_back = !m1_back; } m1_speed += 10; } else m1_speed -= 20; if(button_is_pressed(BUTTON_C)) { if(m2_speed == 0) { delay_ms(200); // If the button is pressed quickly when the motor is off, // reverse direction. if(!button_is_pressed(BUTTON_C)) m2_back = !m2_back; } m2_speed += 10; } else m2_speed -= 20; if(m1_speed < 0) m1_speed = 0; if(m1_speed > 255) m1_speed = 255; if(m2_speed < 0) m2_speed = 0; if(m2_speed > 255) m2_speed = 255; // 255/26 = 9, so this gives values in the range of 0 to 9 m1_char = bar_graph_characters[m1_speed / 26]; m2_char = bar_graph_characters[m2_speed / 26]; print_character(m1_char); print_character(m1_back ? 'a' : 'A'); print_character(m1_char); lcd_goto_xy(5,0); print_character(m2_char); print_character(m2_back ? 'c' : 'C'); print_character(m2_char); set_motors(m1_speed * (m1_back ? -1 : 1), m2_speed * (m2_back ? -1 : 1)); delay_ms(50); }