For context: The code is to control a servo motor through an RC controller (Brand: Radiomaster Boxer), however i got an error while compiling in Arduino IDE
Error is : 'SbusRx does not name a type'
Here's the code:
#include "sbus.h"
#include <Servo.h>
Servo ch[12]; //Create array for 12 servo
SbusRx sbusx(&Serial6); //Since Rx and Tx connected to pin 24 (TX6) & pin 25 (RX6)
unsigned long int timex; //need this to make blink status onboard LED
void setup() {
// put your setup code here, to run once:
pinMode(13,OUTPUT);
digitalWrite(13,LOW);
//attach the 12 servo to pin 0 - 12
for (int i = 0; i <12; i++){
ch.attach(i+2);
}
ch[11].attach(12);
sbusx.Begin();
timex=millis();
}
void loop() {
// put your main code here, to run repeatedly:
if (sbusx.Read()) {
digitalWrite(13,HIGH);
//get 12 channels from sbus and convert them as servo signal
//our RC channels have range 174 - 1811, and servo range 544 - 2400 (can read from Arduino site)
//but for safety purpose, we set the servo range to 700 - 2300, hence midpoint is 1500 ((2300 - 700) / 2)
//can get channel value using sbusx.rx_channels
for (int i=0;i<12; i++) {
int val = map(sbusx.rx_channels(), 174, 1811, 700, 2300);
ch.writeMicroseconds(val);
}
} else {
blinks(true);
}
}
void blinks(bool en_blink) {
if (en_blink) {
if ((millis()-timex)>1000) { //its same as delay (1000)
digitalWrite(13,!digitalRead(13));
timex = millis();
}
}
}
Error is : 'SbusRx does not name a type'
Here's the code:
#include "sbus.h"
#include <Servo.h>
Servo ch[12]; //Create array for 12 servo
SbusRx sbusx(&Serial6); //Since Rx and Tx connected to pin 24 (TX6) & pin 25 (RX6)
unsigned long int timex; //need this to make blink status onboard LED
void setup() {
// put your setup code here, to run once:
pinMode(13,OUTPUT);
digitalWrite(13,LOW);
//attach the 12 servo to pin 0 - 12
for (int i = 0; i <12; i++){
ch.attach(i+2);
}
ch[11].attach(12);
sbusx.Begin();
timex=millis();
}
void loop() {
// put your main code here, to run repeatedly:
if (sbusx.Read()) {
digitalWrite(13,HIGH);
//get 12 channels from sbus and convert them as servo signal
//our RC channels have range 174 - 1811, and servo range 544 - 2400 (can read from Arduino site)
//but for safety purpose, we set the servo range to 700 - 2300, hence midpoint is 1500 ((2300 - 700) / 2)
//can get channel value using sbusx.rx_channels
for (int i=0;i<12; i++) {
int val = map(sbusx.rx_channels(), 174, 1811, 700, 2300);
ch.writeMicroseconds(val);
}
} else {
blinks(true);
}
}
void blinks(bool en_blink) {
if (en_blink) {
if ((millis()-timex)>1000) { //its same as delay (1000)
digitalWrite(13,!digitalRead(13));
timex = millis();
}
}
}