//Serial Test // This is a sample/test program to show the basic functions and software configuration of // the Unified Microsystems ATS-1 Arduino compatible Terminal Shield (www.unifiedmicro.com) // The ATS-1 acts like a miniature ASCII terminal. Characters sent to the transmit line will be // printed out on the 16X2 LCD screen. There are 6 buttons. Pressing a button will send an ASCII 1-6 // corresponding to the button pressed. // This program prints out a message saying what button is pressed. Buttons 4-6 also control the buzzer and LED. // // Gary C. Sutcliffe // November 2011 // Rev. 1.01 ///ATS-1 Demo Program by Gary C. Sutcliffe is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License. //These are some of the commands that control the ATS-1. These are binary values so Serial.print with BYTE modifier must be used #define BELL 0x07 //Character to send to the ATS-1 to generate a beep #define CLS 0x01 //Character to send to the ATS-1 to clear the LCD and home the cursor #define LED_ON 0x11 //Character to send to the ATS-1 to turn LED on #define LED_OFF 0x12 //Character to send to the ATS-1 to turn LED off void setup() { Serial.begin(4800); // opens serial port, sets data rate to 4800 baud } void loop() { char ch; //variable for holding key press value Serial.print(CLS,BYTE); //clears the LCD display and puts cursor in upper left corner Serial.print(LED_OFF,BYTE); //start with the ATS-1 LED turned off Serial.println("Hello, Arduino!"); Serial.print(BELL,BYTE); //generates a 1/3 second beep Serial.print("Press a button>"); while(1) { while(Serial.available() == 0); //wait unit a key is pressed ch = Serial.read(); //Get the number of the key pressed switch(ch) //print out the switch number of the switch pressed, also some special things for SW 4,5 &6 { case '1': Serial.print("\rSW1 ^ "); break; case '2': Serial.print("\rSW2 > "); break; case '3': Serial.print("\rSW3 V "); break; case '4': Serial.print("\rSW4 < Beep "); Serial.print(BELL,BYTE); //Also send a beep break; case '5': Serial.print("\rSW5 F1 LED On "); Serial.print(LED_ON,BYTE); //Also turn LED ON break; case '6': Serial.print("\rSW6 F2 LED Off"); Serial.print(LED_OFF,BYTE ); //Also turn LED OFF break; default: //should never get here, but it is good programming practice to cover any other case. break; } //end of switch-case statements } // end of main while loop } // End of loop()