Skip to content

Commit

Permalink
Change default flag to newline character, add default constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
alextaujenis committed Jan 9, 2016
1 parent 1be5cd2 commit 4bb94f7
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#Arduino Serial Manager Library v1.0.0-alpha.2
#Arduino Serial Manager Library v1.0.0-alpha.3
A simple interface for serial communication.

* [Documentation](http://robotsbigdata.com/docs-arduino-serial-manager.html)
Expand Down
6 changes: 4 additions & 2 deletions examples/basic_serial_protocol/basic_serial_protocol.ino
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Arduino RBD Serial Manager Library v1.0.0-alpha.2 Example - Quickly define and consume an event-based serial protocol.
// Arduino RBD Serial Manager Library v1.0.0-alpha.3 Example - Quickly define and consume an event-based serial protocol.
// https://github.com/alextaujenis/RBD_SerialManager
// Copyright 2016 Alex Taujenis
// MIT License
Expand All @@ -12,12 +12,14 @@ void setup() {
}

void loop() {
// example commands: on; pwm,123;
// you must set the serial monitor to include a newline with each command
if(serial_manager.onReceive()) {
// example command: on
if(serial_manager.isCmd("on")) {
serial_manager.println("IT'S ON!");
}

// example command: pwm,123
if(serial_manager.isCmd("pwm")) {
int value = serial_manager.getParam().toInt();
serial_manager.print("SET PWM ");
Expand Down
10 changes: 6 additions & 4 deletions examples/led_serial_protocol/led_serial_protocol.ino
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Arduino RBD Serial Manager Library v1.0.0-alpha.2 Example - Control the built-in Arduino led with serial commands: on; off; pwm,255;
// Arduino RBD Serial Manager Library v1.0.0-alpha.3 Example - Control the built-in Arduino led with serial commands: on off pwm,255
// https://github.com/alextaujenis/RBD_SerialManager
// Copyright 2016 Alex Taujenis
// MIT License
Expand All @@ -15,21 +15,23 @@ void setup() {
}

void loop() {
// you must set the serial monitor to include a newline with each command
if(usb.onReceive()) {
// example serial command: on;
// example serial command: on
if(usb.isCmd("on")) {
light.on();
}

// example serial command: off;
// example serial command: off
if(usb.isCmd("off")) {
light.off();
}

// example serial command: pwm,123;
// example serial command: pwm,123
if(usb.isCmd("pwm")) {
int pwm = usb.getParam().toInt();
light.setBrightness(pwm);
}
}
light.update();
}
12 changes: 6 additions & 6 deletions examples/servo_serial_protocol/servo_serial_protocol.ino
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Arduino RBD Serial Manager Library v1.0.0-alpha.2 Example - Control the rotation of a servo with serial commands: up; down; move,90;
// Arduino RBD Serial Manager Library v1.0.0-alpha.3 Example - Control the rotation of a servo with serial commands: up down move,90
// https://github.com/alextaujenis/RBD_SerialManager
// Copyright 2016 Alex Taujenis
// MIT License
Expand All @@ -14,23 +14,23 @@ void setup() {
}

void loop() {
servo.update();

// you must set the serial monitor to include a newline with each command
if(usb.onReceive()) {
// example serial command: up;
// example serial command: up
if(usb.isCmd("up")) {
servo.moveToDegrees(180);
}

// example serial command: down;
// example serial command: down
else if(usb.isCmd("down")) {
servo.moveToDegrees(0);
}

// example serial command: move,90;
// example serial command: move,90
else if(usb.isCmd("move")) {
int _position = usb.getParam().toInt();
servo.moveToDegrees(_position);
}
}
servo.update();
}
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=RBD_SerialManager
version=1.0.0-alpha.2
version=1.0.0-alpha.3
author=Alex Taujenis <alex.taujenis@gmail.com>
maintainer=Alex Taujenis <alex.taujenis@gmail.com>
sentence=A simple interface for serial communication.
Expand Down
4 changes: 3 additions & 1 deletion src/RBD_SerialManager.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Arduino RBD Serial Manager Library v1.0.0-alpha.2 - A simple interface for serial communication.
// Arduino RBD Serial Manager Library v1.0.0-alpha.3 - A simple interface for serial communication.
// https://github.com/alextaujenis/RBD_SerialManager
// Copyright 2016 Alex Taujenis
// MIT License
Expand All @@ -7,6 +7,8 @@
#include <RBD_SerialManager.h> // https://github.com/alextaujenis/RBD_SerialManager

namespace RBD {
SerialManager::SerialManager() {}

void SerialManager::start() {
Serial.begin(115200);
}
Expand Down
5 changes: 3 additions & 2 deletions src/RBD_SerialManager.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Arduino RBD Serial Manager Library v1.0.0-alpha.2 - A simple interface for serial communication.
// Arduino RBD Serial Manager Library v1.0.0-alpha.3 - A simple interface for serial communication.
// https://github.com/alextaujenis/RBD_SerialManager
// Copyright 2016 Alex Taujenis
// MIT License
Expand All @@ -11,6 +11,7 @@
namespace RBD {
class SerialManager {
public:
SerialManager();
void start();
void setFlag(char value);
void setDelimiter(char value);
Expand All @@ -25,7 +26,7 @@ namespace RBD {
private:
int _position;
char _char;
char _flag = ';';
char _flag = '\n'; // you must set the serial monitor to include a newline with each command
char _delimiter = ',';
String _buffer = "";
String _value = "";
Expand Down

0 comments on commit 4bb94f7

Please sign in to comment.