// TellyMateShield_ReadTest.pde // // A very simple self-contained sketch to demonstrate character reading. // It continually "encodes" the contents of the TellyMate screen by rotating // each (non-space) character to the next in the ascii set. #define BAUD_RATE 57600 #define CHAR_ESC "\x1B" void setup() { Serial.begin( BAUD_RATE ) ; // set to 57600 baud tellymate_cursor_show( false ) ; tellymate_screen_clear() ; tellymate_enabletransmit() ; Serial.print( CHAR_ESC "Q" ) ; // output diagnostics delay(5000); Serial.flush(); // ensure that the RX buffer is empty. } void loop() { // loop through every character on the tellymate screen... for( uint8_t row = 0 ; row < 25 ; row++ ) { for( uint8_t col = 0 ; col < 38 ; col++ ) { tellymate_cursor_move( row , col ) ; //move the cursor to the position we want to read int c = tellymate_cursor_read(); // read the character under the cursor if ( c > 32 ) // only encode 'normal' characters { c = c + 1 ; // "encode" the character (by adding 1 to it!) if (c > 255) c = 33 ; // if it's gone past 255, loop it back to the "!" character. Serial.print( (char) c ) ; // output the newly encoded character } } } } int tellymate_cursor_read() { // | Serial.print( CHAR_ESC "|" ); return( tellymate_get_response() ) ; } int tellymate_get_response() { // The tellymate has been asked to send back some data. // This routine waits up to 50 bit durations for a response. // (enough for the tellymate to receive the instruction and send the byte back) // // Note that because the Arduino has a large serial receive buffer, make sure that it's empty // before asking for data, otherwise this routine will pick up previously received characters. // (which can be very confusing!) for( uint8_t i = 0 ; i < 50 ; i++ ) { if (Serial.available() > 0) return ( Serial.read() ) ; // If a character was received, return it. delayMicroseconds( 1000000 / BAUD_RATE ) ; // wait for approximately one bit duration } return -1 ; // no character was received in the time limit. Return -1 (as per Serial.read() when there is no data) } void tellymate_enabletransmit() { // ~~~~ // care should be taken not to embed the whole 'enable-transmit' code in the compiled sketch // (otherwise the TellyMate may become 'transmit enabled' during the upload verification process) // (see 'Retrieving data from the TellyMate' in the User Guide) // The code below is suitable, and will not cause any problems during sketch upload. Serial.print( CHAR_ESC ) ; for( byte i = 0 ; i < 4 ; i++ ){ Serial.print( '~' ) ; } } void tellymate_cursor_move( uint8_t row , uint8_t col ) { // Yrc Serial.print( CHAR_ESC "Y" ) ; Serial.print((char)(32 + row)) ; Serial.print((char)(32 + col)) ; } void tellymate_cursor_show( bool show ) { // e or f Serial.print( CHAR_ESC ) ; Serial.print( show?'e':'f' ) ; } void tellymate_screen_clear( void ) { // E Serial.print( CHAR_ESC "E" ); }