Skip to content

Instantly share code, notes, and snippets.

@laclefyoshi
Created December 25, 2010 04:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save laclefyoshi/754682 to your computer and use it in GitHub Desktop.
Save laclefyoshi/754682 to your computer and use it in GitHub Desktop.
Arduino code for controlling GLCD through Serial port
/**
Copyright: (c) SAEKI Yoshiyasu
License : MIT-style license
<http://www.opensource.org/licenses/mit-license.php>
last updated: 2010/12/24
**/
#include <ks0108.h>
int inByte = 0;
unsigned int sx; // 0 ~ 128
unsigned int sy; // 0 ~ 64
unsigned int dx;
unsigned int dy;
char pairs[17]; // sx,sy:dx,dy;
void setup(){
Serial.begin(9600);
GLCD.Init(NON_INVERTED);
}
void loop(){
if(Serial.available() > 0) {
int i = 0;
do {
inByte = Serial.read();
pairs[i++] = (char)inByte;
if(inByte == ';') {
break;
} else if(inByte == 'c') {
GLCD.ClearScreen();
break;
} else if(inByte == '.') {
Serial.println(".");
break;
}
} while((inByte >= '0' && inByte <= '9') ||
inByte == ':' || inByte == ',');
pairs[--i] = '\0';
Serial.println(pairs);
if(sscanf(pairs, "%d,%d:%d,%d", &sx, &sy, &dx, &dy) == 4) {
GLCD.DrawLine(sx, sy, dx, dy, BLACK);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment