Skip to content

Instantly share code, notes, and snippets.

@priithansen
Created March 30, 2012 12:45
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 priithansen/2251279 to your computer and use it in GitHub Desktop.
Save priithansen/2251279 to your computer and use it in GitHub Desktop.
Makibot Arduino code
boolean stringComplete = false; // whether the string is complete
String inputString = "";
void setup() {
// test pin
pinMode(10, OUTPUT); // Vasakule
pinMode(9, OUTPUT); // Paremale
// initialize serial:
Serial.begin(9600);
}
void loop() {
// print the string when a newline arrives:
if (stringComplete) {
if (inputString == "e") {
digitalWrite(10, HIGH);
digitalWrite(9, HIGH);
}
if (inputString == "v") {
digitalWrite(10, HIGH);
}
if (inputString == "p") {
digitalWrite(9, HIGH);
}
if (inputString == "s") {
digitalWrite(10, LOW);
digitalWrite(9, LOW);
}
inputString = "";
stringComplete = false;
}
}
/*
SerialEvent occurs whenever a new data comes in the
hardware serial RX. This routine is run between each
time loop() runs, so using delay inside loop can delay
response. Multiple bytes of data may be available.
*/
void serialEvent() {
while (Serial.available()) {
// get the new byte:
char suund = (char)Serial.read();
inputString += suund;
stringComplete = true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment