Advertisement
MattRichardson

TellyMate Etch-A-Sketch

Oct 20th, 2011
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.84 KB | None | 0 0
  1. #define CHAR_ESC "\x1B"
  2.  
  3. int x;
  4. int y;
  5.  
  6. void setup()
  7. {
  8.   Serial.begin(57600); // set to 57600 baud
  9.   screen_clear();
  10.   cursor_show(false);
  11. }
  12.  
  13. void loop()
  14. {
  15.   x = map(analogRead(0), 0, 1023, 0, 25); // determine x from the pot
  16.   y = map(analogRead(1), 0, 1023, 0, 38); // determine y from the pot
  17.   cursor_move( x , y ) ; // move to those coordinates
  18.   Serial.print( '\xDB' ) ; // draw a block
  19.  
  20. }
  21.  
  22. // Helper functions from the TellyMate example code:
  23.  
  24. void cursor_move( uint8_t row , uint8_t col )
  25. { // <ESC>Yrc
  26.   Serial.print( CHAR_ESC "Y" ) ;
  27.   Serial.print((unsigned char)(32 + row)) ;
  28.   Serial.print((unsigned char)(32 + col)) ;
  29. }
  30.  
  31. void cursor_show( bool show )
  32. { // <ESC>e or <ESC>f
  33.   Serial.print( CHAR_ESC ) ;
  34.   Serial.print( show?'e':'f' ) ;
  35. }
  36.  
  37. void screen_clear( void )
  38. { // <ESC>E
  39.   Serial.print( CHAR_ESC "E" );
  40. }
  41.  
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement