/* serialVGA - Test program for communicating with Hobbytronics serialVGA board Creates 5 windows and displays data Copyright www.hobbytronics.co.uk 2012 */ unsigned long currentTime; unsigned long loopTime; unsigned int counter=0; unsigned long number_sum=0; unsigned long number_avg=0; // Window Creation strings (without initial escape sequence) char header[] = {"w,1,0,0,100,3,1,"}; // no title char window2[] = {"w,2,0,3,70,32,1,Raw Data Display"}; char window3[] = {"w,3,70,3,30,32,1,Calculated Values"}; char window4[] = {"w,4,0,35,100,14,1,Terminal Input"}; char footer[] = {"w,5,0,49,100,1,0,"}; // no border, no title // Line colour strings (without initial escape sequence) char header_colour[] = {"l,0,2,222,101"}; // White text on purple lines 0-2 char window4_colour[] = {"l,35,48,222,001"}; // white text on blue lines 35-48 char footer_colour[] = {"l,49,49,000,111"}; // black text on grey line 49 void vga_command(char *command_str) { // Function to easily send command to VGA board Serial.print("^["); // send escape sequence Serial.println(command_str); // send Command string // Most commands don't take very long, but need a small delay to complete // The Reboot cammand needs 2 seconds if(command_str[0]=='r') delay(2000); // Wait 2 seconds for reboot if((command_str[0]=='w') || (command_str[0]=='p')) delay(20); // Small delay for window commands delay(2); // Other commands need a tiny delay } void vga_inverse(char *text_str) { // Function to write inverse characters to VGA board // Makes bit 7 of each character a 1 unsigned int i; for(i=0;text_str[i] != '\0';i++) { text_str[i]=text_str[i] | 0x80; } Serial.print(text_str); } void setup() { // initialize Serial.begin(9600); // Set baud rate for serialVGA board vga_command("r"); // reboot VGA board vga_command(header); // Create header Serial.print(" "); Serial.print("HobbyTronics serialVGA Driver board Demonstration"); vga_command(window2); // Create Window2 vga_command(window3); // Create Window3 vga_command(window4); // Create Window4 vga_command("c,4,1"); // Turn text cursor ON in window 4 vga_command(footer); // Create footer Serial.print(" Hobbytronics Ltd www.hobbytronics.co.uk"); Serial.print(" serialVGA demo"); vga_command(header_colour); // header window colour vga_command(window4_colour); // window 4 colour vga_command(footer_colour); // footer window colour currentTime = millis(); loopTime = currentTime; } void loop() { currentTime = millis(); if(currentTime >= (loopTime + 500)){ // send every half second loopTime = currentTime; // Updates loopTime vga_command("f,2"); // Set Window2 as focus Serial.print("This is data - "); // print data Serial.println(counter, DEC); vga_command("f,3"); // Set Window3 as focus vga_command("p,0,0"); // Set Window3 text position to 0,0 vga_inverse("Summary of Data"); // print title in reverse Serial.print("\r\n\r\n"); // send 2x CR to move down 2 lines Serial.print("Largest Number - "); // print data Serial.println(counter, DEC); Serial.print("SUM of Numbers - "); // print data Serial.println(number_sum, DEC); Serial.print("AVG of Numbers - "); // print data Serial.println(number_avg, DEC); counter++; number_sum+=counter; number_avg=number_sum/counter; } if (Serial.available() > 0) { // Data received into Arduino board, echo'd out to Window 4 (command window) int inByte = Serial.read(); vga_command("f,4"); // Set Window4 as focus Serial.write(inByte); } }