/* Serial LCD //These comments I received from Joel Murphy * * communicate with Parallax Serial LCD screen * using the pin 4 on the ATMEL (2 on Arduino). it will work on pin 3 (Arduino tx pin 1). * Serial Signal needs to be TRUE. This code modifies SoftSerial from the Playground. * Delay timing in uS tweaked to perfection +-2 * */ // TEST ALL THREE OF THESE TIMING DELAYS AND TWEAK THEM AS NEEDED #define bit24 396 //timing for 2.4Kbaud #define halfBit24 198 // 1/2400 = .000416 #define bit96 100 //timing for 9.6Kbaud #define halfBit96 50 // 1/9600 = .000104 #define bit192 47 //timing for 19.2Kbaud #define halfBit192 23 // 1/19200 = .000052 //end of comments and defined variables from Joel Murphy //These are the 4 custom characters I created to draw an approximate sine wave on the LCD //First value is choosing to assign values to a custom character //Next 8 values are the 8 rows for each character on the LCD //Last value is telling the LCD to print my new custom character byte first [11] = {248, 3, 4, 8, 16, 0, 0, 0, 0, 0}; byte second [11] = {249, 24, 4, 2, 1, 0, 0, 0, 0, 1}; byte third [11] = {250, 0, 0, 0, 0, 16, 8, 4, 3, 2}; byte fourth [11] = {251, 0, 0, 0, 0, 1, 2, 4, 24, 3}; int LCD = 2; //LCD control line byte outByte = 0; int i; int count = 0; //this count helps with the animation of the custom characters void setup(){ pinMode (LCD,OUTPUT); digitalWrite(LCD,HIGH); delay(1000); SWprint(12); //clear lcd and reset cursor to 0/0 SWprint(128); //return to line 0, position 0 delay(100); SWprint(17); //turn on backlight delay(100); } //this loop counts out through the number of frames it is going through before it moves to the //next permutation of the sine wave void loop(){ for(count=0; count<=32; count++) { if (count <= 7) { getOne(); delay(5); } else if (count<=15) { getTwo(); delay(5); } else if (count<=23) { getThree(); delay(5); } else if (count <=31) { getFour(); delay(5); } else if (count == 31) { count=0; delay(1000); } } } //by rotating backwards through each of the the different permutations, it gives the look that //the sine wave is moving forwards through the LCD screen void getOne(){ for(i=0; i<=9; i++){ SWprint(first[i]); } for(i=0; i<=9; i++){ SWprint(second[i]); } for(i=0; i<=9; i++){ SWprint(third[i]); } for(i=0; i<=9; i++){ SWprint(fourth[i]); } } void getTwo(){ for(i=0; i<=9; i++){ SWprint(fourth[i]); } for(i=0; i<=9; i++){ SWprint(first[i]); } for(i=0; i<=9; i++){ SWprint(second[i]); } for(i=0; i<=9; i++){ SWprint(third[i]); } } void getThree(){ for(i=0; i<=9; i++){ SWprint(third[i]); } for(i=0; i<=9; i++){ SWprint(fourth[i]); } for(i=0; i<=9; i++){ SWprint(first[i]); } for(i=0; i<=9; i++){ SWprint(second[i]); } } void getFour(){ for(i=0; i<=9; i++){ SWprint(second[i]); } for(i=0; i<=9; i++){ SWprint(third[i]); } for(i=0; i<=9; i++){ SWprint(fourth[i]); } for(i=0; i<=9; i++){ SWprint(first[i]); } } //this is code I received from Joel Murphy //this is what keeps time for the serial communication with the LCD void SWprint(byte data){ byte mask; digitalWrite(LCD,LOW); //startbit delayMicroseconds(bit96); for (mask = 0x01; mask>0; mask <<= 1) { if ((data & mask) > 0){ // choose bit digitalWrite(LCD,HIGH); // send 1 }else{ digitalWrite(LCD,LOW); // send 0 } delayMicroseconds(bit96); } //stop bit digitalWrite(LCD, HIGH); delayMicroseconds(bit96); }