Created
November 28, 2015 14:28
Monitor serial for commands
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <LiquidCrystal.h> | |
// tell the library which pins the LCD is connected on | |
LiquidCrystal lcd(12,11,10,5,4,3,2); | |
void setup() | |
{ | |
// initialize the serial port to 9600 baud (it's fast enough) | |
Serial.begin(9600); | |
// initialize the lcd to 16 columns, 2 rows | |
lcd.begin(16,2); | |
lcd.autoscroll(); | |
} | |
void loop() | |
{ | |
int input = 0; | |
// if there is data available | |
if (Serial.available()) | |
{ | |
// wait a bit for it all to arrive... | |
delay(100); | |
// clear the LCD | |
lcd.clear(); | |
// enter a loop until there's no data left to read | |
while (Serial.available() > 0) | |
{ | |
// read a character off the serial port | |
input = Serial.read(); | |
switch (input) | |
{ | |
case 1: // if it's a 1, set the cursor position to the upper left | |
lcd.setCursor(0,0); | |
break; | |
case 2: // if it's a 2, set the cursor position to the lower left | |
lcd.setCursor(0,1); | |
break; | |
case 0: // if it's a 0, we're at the end of the data anyway, just break | |
break; | |
default: // otherwise, just print the character | |
lcd.write(input); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment