Skip to content

Instantly share code, notes, and snippets.

@mash
Created August 14, 2013 02:05
Show Gist options
  • Save mash/6227440 to your computer and use it in GitHub Desktop.
Save mash/6227440 to your computer and use it in GitHub Desktop.
#include "Arduino.h"
#include <Servo.h>
Servo servo;
char line[10];
int line_index;
void setup() {
Serial.begin(9600);
Serial.println("started");
servo.attach(9);
line_index = 0;
memset(line, 0, sizeof(line));
}
void loop() {
// check for input from the user
if ( Serial.available() ) {
line_index = 0;
memset(line, 0, sizeof(line));
int ret = Serial.readBytes( line, sizeof(line) );
Serial.print("bytes: 0x"); Serial.println(ret, HEX);
Serial.print("read: 0x");
for (line_index=0; line_index<ret; line_index++){
Serial.print(line[line_index]);
}
Serial.println("");
int out;
ret = sscanf(line, "%d", &out);
Serial.print("out: "); Serial.println(out);
servo.write(out);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment