Skip to content

Commit

Permalink
Add print and println, refactor examples
Browse files Browse the repository at this point in the history
  • Loading branch information
alextaujenis committed Jan 4, 2016
1 parent 1a788ab commit 6738e18
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 18 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.1
#Arduino Serial Manager Library v1.0.0-alpha.2
A simple interface for serial communication.

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

#include <RBD_SerialManager.h> // https://github.com/alextaujenis/RBD_SerialManager
Expand All @@ -12,8 +12,16 @@ void setup() {
}

void loop() {
// example commands: on; pwm,123;
if(serial_manager.onReceive()) {
// example serial command: hello world;
Serial.println(serial_manager.getValue());
if(serial_manager.isCmd("on")) {
serial_manager.println("IT'S ON!");
}

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

#include <RBD_SerialManager.h> // https://github.com/alextaujenis/RBD_SerialManager
#include <RBD_Timer.h> // https://github.com/alextaujenis/RBD_Timer
#include <RBD_Light.h> // https://github.com/alextaujenis/RBD_Light
#include <RBD_SerialManager.h> // https://github.com/alextaujenis/RBD_SerialManager

RBD::SerialManager usb;
RBD::Light light(13);
RBD::SerialManager usb;

void setup() {
usb.start();
Expand Down
8 changes: 4 additions & 4 deletions examples/servo_serial_protocol/servo_serial_protocol.ino
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Arduino RBD Serial Manager Library v1.0.0-alpha.1 Example - Control the rotation of a servo with serial commands: up; down; move,90;
// Arduino RBD Serial Manager Library v1.0.0-alpha.2 Example - Control the rotation of a servo with serial commands: up; down; move,90;
// https://github.com/alextaujenis/RBD_SerialManager
// Copyright 2015 Alex Taujenis
// Copyright 2016 Alex Taujenis
// MIT License

#include <RBD_SerialManager.h> // https://github.com/alextaujenis/RBD_SerialManager
#include <RBD_Servo.h> // https://github.com/alextaujenis/RBD_Servo
#include <RBD_SerialManager.h> // https://github.com/alextaujenis/RBD_SerialManager

RBD::SerialManager usb;
RBD::Servo servo(2, 700, 2300); // digital pin 2, 700ms - 2300ms pulse range
RBD::SerialManager usb;

void setup() {
usb.start();
Expand Down
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.1
version=1.0.0-alpha.2
author=Alex Taujenis <[email protected]>
maintainer=Alex Taujenis <[email protected]>
sentence=A simple interface for serial communication.
Expand Down
4 changes: 2 additions & 2 deletions src/RBD_SerialManager.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Arduino RBD Serial Manager Library v1.0.0-alpha.1 - A simple interface for serial communication.
// Arduino RBD Serial Manager Library v1.0.0-alpha.2 - A simple interface for serial communication.
// https://github.com/alextaujenis/RBD_SerialManager
// Copyright 2015 Alex Taujenis
// Copyright 2016 Alex Taujenis
// MIT License

#include <Arduino.h>
Expand Down
6 changes: 4 additions & 2 deletions src/RBD_SerialManager.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Arduino RBD Serial Manager Library v1.0.0-alpha.1 - A simple interface for serial communication.
// Arduino RBD Serial Manager Library v1.0.0-alpha.2 - A simple interface for serial communication.
// https://github.com/alextaujenis/RBD_SerialManager
// Copyright 2015 Alex Taujenis
// Copyright 2016 Alex Taujenis
// MIT License

#ifndef RBD_SERIAL_MANAGER
Expand All @@ -20,6 +20,8 @@ namespace RBD {
String getParam();
bool isCmd(String value);
bool isParam(String value);
template <typename T> void print(T value){Serial.print(value);}
template <typename T> void println(T value){Serial.println(value);}
private:
int _position;
char _char;
Expand Down

0 comments on commit 6738e18

Please sign in to comment.