Skip to content

Commit

Permalink
Updated examples
Browse files Browse the repository at this point in the history
  • Loading branch information
flybrianfly committed Jul 27, 2018
1 parent 51bf77e commit 02100fc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 26 deletions.
41 changes: 20 additions & 21 deletions examples/AIN_SBUS_example/AIN_SBUS_example.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
SBUS_example.ino
Brian R Taylor
[email protected]
2017-01-13
Copyright (c) 2016 Bolder Flight Systems
Expand All @@ -29,7 +28,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SO
#include <TimerOne.h>
#include "SBUS.h"

// a SBUS object, which is on Teensy hardware
// a SBUS object, which is on hardware
// serial port 1
SBUS x8r(Serial1);

Expand All @@ -42,14 +41,14 @@ void setup() {
Serial.begin(115200);

// begin the SBUS communication
x8r.begin();
x8r.begin();

// setup the analog read resolution to 16 bits
analogReadResolution(16);
// setup the analog read resolution to 16 bits
analogReadResolution(16);

// setup an interrupt to send packets every 9 ms
Timer1.initialize(9000);
Timer1.attachInterrupt(sendSBUS);
// setup an interrupt to send packets every 9 ms
Timer1.initialize(9000);
Timer1.attachInterrupt(sendSBUS);
}

void loop() {
Expand All @@ -63,20 +62,20 @@ void sendSBUS() {
uint16_t channels[16];

// read the analog inputs
for(uint8_t i = 14; i < 24; i++) {
ain[i-14] = analogRead(i);
}

// linearly map the analog measurements (0-65535)
// to the SBUS commands (172-1811)
for(uint8_t i = 0; i < 10; i++) {
channels[i] = (uint16_t)(((float)ain[i]) * scaleFactor + bias);
Serial.print(channels[i]); // print the channel command (172-1811)
Serial.print("\t");
}
Serial.println();
for(uint8_t i = 14; i < 24; i++) {
ain[i-14] = analogRead(i);
}

// linearly map the analog measurements (0-65535)
// to the SBUS commands (172-1811)
for(uint8_t i = 0; i < 10; i++) {
channels[i] = (uint16_t)(((float)ain[i]) * scaleFactor + bias);
Serial.print(channels[i]); // print the channel command (172-1811)
Serial.print("\t");
}
Serial.println();

// write the SBUS packet to an SBUS compatible servo
x8r.write(&channels[0]);
x8r.write(&channels[0]);
}

9 changes: 4 additions & 5 deletions examples/SBUS_example/SBUS_example.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
SBUS_example.ino
Brian R Taylor
[email protected]
2016-09-21
Copyright (c) 2016 Bolder Flight Systems
Expand Down Expand Up @@ -35,14 +34,14 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SO

#include "SBUS.h"

// a SBUS object, which is on Teensy hardware
// a SBUS object, which is on hardware
// serial port 1
SBUS x8r(Serial1);

// channel, fail safe, and lost frames data
uint16_t channels[16];
uint8_t failSafe;
uint16_t lostFrames = 0;
bool failSafe;
bool lostFrame;

void setup() {
// begin the SBUS communication
Expand All @@ -52,7 +51,7 @@ void setup() {
void loop() {

// look for a good SBUS packet from the receiver
if(x8r.read(&channels[0], &failSafe, &lostFrames)){
if(x8r.read(&channels[0], &failSafe, &lostFrame)){

// write the SBUS packet to an SBUS compatible servo
x8r.write(&channels[0]);
Expand Down

0 comments on commit 02100fc

Please sign in to comment.