Skip to content
Snippets Groups Projects
Commit d0f949c4 authored by Dave Murray-Rust's avatar Dave Murray-Rust
Browse files

Documenting and tidying

parent d54dd14d
No related branches found
No related tags found
No related merge requests found
......@@ -25,4 +25,74 @@ Because this is not a single sketch, development needs a bit of thinking about.
# Usage
The library is designed to be used within normal Arduino sketches.
The library is designed to be used within normal Arduino sketches. It wraps up most of the business of connecting to MQTT etc. in a `WallVis` class, and you then give it a bunch of `Behaviours` that do interesting things.
## Setup
The node is set up with all of the connection information for the WiFi network and for NodeRE, e.g.:
```arduino
#include <WallVis.h>
WallVis node(
"new001", // Our ID
"WallVisNet", //Wifi Access Point
"wallvisAP", //WiFi Password
"192.168.4.1",//IP address of Node RED server
1883 //Port for Node RED server
);
```
A very simple sketch would then simply initialise this, and call its main function in a loop:
```
void setup()
{
Serial.begin(115200);
//Initialise the whole infrastructure
node.init();
}
void loop()
{
node.vis_loop();
}
```
## Adding behaviours
However, this would not do anything useful - it needs to know what to do. So we should add some `Behaviour`s. Each behaviour is one thing that the node knows how to do - set a number of LEDs to be active, move a servo to a certain angle, wiggle a servo for a bit etc.
Any number of behaviours can be added. They each need a unique name, so that they can be called correctly. Behaviours can also have parameters. In this example, we are adding three different behaviours, that all wiggle a servo. They have different speeds of wiggling, though (the last parameter) and different names. (`s1` is the Servo object they are working on).
```
node.add(new ServoWiggle(s1, "wiggle") );
node.add(new ServoWiggle(s1, "slow_wiggle", 10) );
node.add(new ServoWiggle(s1, "fast_wiggle", 1) );
```
Now, the node will respond to three commands - `wiggle`, `slow_wiggle` and `fast_wiggle`.
You can see a full example of this in the `ExampleNode` sketch.
## Calling Behaviours
Behaviours can currently be called in two ways:
* via Node RED, by sending a message on the channel. So, instead of sending '100' to make the node wiggle, now you have to sent 'wiggle 100'.
* you can also do this using the Arduino serial monitor, to make it easier to test
Each `Behaviour` has a unique name, and some number of parameters (mostly none, or one).
# Behaviours
Behaviours are defined as classes. Each class has a unique name, and a constructor that takes several arguments. These are for things that should not change, e.g. the Servo object that is being wiggled. When the behaviour is called, it is called with arguments for *just that action*. So, for wiggling a servo, the constructor is:
`ServoWiggle( <servo_object>, <name>, <wiggle_speed>)`
When the behaviour is then called, it is given the angle through which to wiggle, so the size of the wiggle can be controlled.
The current set of behaviours and their parameters are:
| Constructor | Called with | Effect |
| ---- | ---- | ---- |
|`ServoWiggle( <servo_object>, <name>, <wiggle_speed> )`|`wiggle <int wiggle_angle>`|wiggles the servo|
#include <Servo.h>
#include <WallVis.h>
#include <Behaviours.h>
WallVis node(
"new001", // Our ID
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment