Skip to content

Commit

Permalink
Update ArduinoBlue examples
Browse files Browse the repository at this point in the history
  • Loading branch information
harbaum committed Jul 13, 2020
1 parent bc46c86 commit 8f68991
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
// CounterPorts/ArduinoBlue
// ftDuino example for ArduinoBlue https://sites.google.com/stonybrook.edu/arduinoble
// The HM10 TXD needs to be connected to C1 of the ftDuino. RXD may be unconnected.
// This demo controls a motor on M1 using the ArduinoBlue joystick throttle (y axis)

// Blueooth using Serial1 re-uses the UART which is normally needed for
// ultrasonic. Thus a local library version without ultrasonic is being used

// This demo needs the ArduinoBlue library. Please install it using the library manager.

#include "Ftduino.h"
#include <ArduinoBlue.h>

ArduinoBlue phone(Serial1);
Expand All @@ -12,9 +19,8 @@ int throttle, steering, sliderVal, button, sliderId;

void setup()
{
ftduino.init();
Serial.begin(9600);
while(!Serial);

Serial1.begin(9600);
};

Expand Down Expand Up @@ -58,6 +64,14 @@ void loop()
Serial.print("Throttle: "); Serial.print(throttle); Serial.print("\tSteering: "); Serial.println(steering);
prevThrottle = throttle;
prevSteering = steering;

// use throttle to control M1
if(throttle >= 50) // 50 ... 99
ftduino.motor_set(Ftduino::O1, Ftduino::LEFT, Ftduino::MAX * (throttle-50) / 49);
else if(throttle <= 48) // 0 ... 48
ftduino.motor_set(Ftduino::O1, Ftduino::RIGHT, Ftduino::MAX * (48-throttle) / 48);
else // 49
ftduino.motor_set(Ftduino::O1, Ftduino::OFF, Ftduino::MAX);
}

// If a text from the phone was sent print it to the serial monitor
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
// ArduinoBlue example for use with HM10 connected via I2C-UART bridge SC16IS750
// I2C_Uart/ArduinoBlue
// ftDuino example for ArduinoBlue https://sites.google.com/stonybrook.edu/arduinoble
// The HM10 needs to be connected via I²C using a SC16IS750 to the ftDuino

// This demo needs the ArduinoBlue library. Please install it using the library manager.

#include "SC16IS750.h"
#include <ArduinoBlue.h>
#include <Ftduino.h>

SC16IS750 i2cuart = SC16IS750(SC16IS750_PROTOCOL_I2C,SC16IS750_ADDRESS_BB);
ArduinoBlue phone(i2cuart);
Expand All @@ -13,8 +18,8 @@ int throttle, steering, sliderVal, button, sliderId;

void setup()
{
ftduino.init();
Serial.begin(9600);
while(!Serial);
i2cuart.begin(9600); //baudrate setting
};

Expand Down Expand Up @@ -58,6 +63,14 @@ void loop()
Serial.print("Throttle: "); Serial.print(throttle); Serial.print("\tSteering: "); Serial.println(steering);
prevThrottle = throttle;
prevSteering = steering;

// use throttle to control M1
if(throttle >= 50) // 50 ... 99
ftduino.motor_set(Ftduino::O1, Ftduino::LEFT, Ftduino::MAX * (throttle-50) / 49);
else if(throttle <= 48) // 0 ... 48
ftduino.motor_set(Ftduino::O1, Ftduino::RIGHT, Ftduino::MAX * (48-throttle) / 48);
else // 49
ftduino.motor_set(Ftduino::O1, Ftduino::OFF, Ftduino::MAX);
}

// If a text from the phone was sent print it to the serial monitor
Expand Down

0 comments on commit 8f68991

Please sign in to comment.