Skip to content

Instantly share code, notes, and snippets.

@mveinot
Created November 28, 2015 14:28
Show Gist options
  • Save mveinot/9f33ec55a20d57bc491f to your computer and use it in GitHub Desktop.
Save mveinot/9f33ec55a20d57bc491f to your computer and use it in GitHub Desktop.
Monitor serial for commands
#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