Skip to content

Instantly share code, notes, and snippets.

@pyxze
Last active February 27, 2017 21:04
Show Gist options
  • Save pyxze/249731cc4325fd8cd4101d46511d0bcb to your computer and use it in GitHub Desktop.
Save pyxze/249731cc4325fd8cd4101d46511d0bcb to your computer and use it in GitHub Desktop.
// This is for the OSEPP 16x2 Arduino LCD Shield
// Also need the library from https://osepp.com/downloads/LCDKeypad.zip
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
//LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
String inData;
void setup() {
lcd.begin(16, 2);
Serial.begin(115200);
}
void loop() {
while (Serial.available() > 0)
{
char recieved = Serial.read();
inData += recieved;
if (recieved == '*')
{
inData.remove(inData.length() - 1, 1);
lcd.setCursor(0,0);
lcd.print(inData);
inData = "";
if(inData == "DIS")
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Disconnected!");
}
}
if (recieved == '#')
{
inData.remove(inData.length() - 1, 1);
lcd.setCursor(0,1);
lcd.print(inData);
inData = "";
}
}
}
# Corresponding Python snippet to show date and time
import serial
import time
import datetime
ser = serial.Serial("COM4", 115200)
while True:
ser.write((datetime.datetime.now().strftime('%x') + "*").encode('ascii'))
ser.write((datetime.datetime.now().strftime('%X') + "#").encode('ascii'))
time.sleep(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment