Skip to content

Commit 8f68991

Browse files
author
harbaum
committed
Update ArduinoBlue examples
1 parent bc46c86 commit 8f68991

2 files changed

Lines changed: 31 additions & 4 deletions

File tree

ftduino/libraries/Ftduino/examples/Bluetooth/CounterPort/ArduinoBlue/ArduinoBlue.ino

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
// CounterPorts/ArduinoBlue
22
// ftDuino example for ArduinoBlue https://sites.google.com/stonybrook.edu/arduinoble
33
// The HM10 TXD needs to be connected to C1 of the ftDuino. RXD may be unconnected.
4+
// This demo controls a motor on M1 using the ArduinoBlue joystick throttle (y axis)
45

6+
// Blueooth using Serial1 re-uses the UART which is normally needed for
7+
// ultrasonic. Thus a local library version without ultrasonic is being used
8+
9+
// This demo needs the ArduinoBlue library. Please install it using the library manager.
10+
11+
#include "Ftduino.h"
512
#include <ArduinoBlue.h>
613

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

1320
void setup()
1421
{
22+
ftduino.init();
1523
Serial.begin(9600);
16-
while(!Serial);
17-
1824
Serial1.begin(9600);
1925
};
2026

@@ -58,6 +64,14 @@ void loop()
5864
Serial.print("Throttle: "); Serial.print(throttle); Serial.print("\tSteering: "); Serial.println(steering);
5965
prevThrottle = throttle;
6066
prevSteering = steering;
67+
68+
// use throttle to control M1
69+
if(throttle >= 50) // 50 ... 99
70+
ftduino.motor_set(Ftduino::O1, Ftduino::LEFT, Ftduino::MAX * (throttle-50) / 49);
71+
else if(throttle <= 48) // 0 ... 48
72+
ftduino.motor_set(Ftduino::O1, Ftduino::RIGHT, Ftduino::MAX * (48-throttle) / 48);
73+
else // 49
74+
ftduino.motor_set(Ftduino::O1, Ftduino::OFF, Ftduino::MAX);
6175
}
6276

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

ftduino/libraries/Ftduino/examples/Bluetooth/I2C_Uart/ArduinoBlue/ArduinoBlue.ino

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1-
// ArduinoBlue example for use with HM10 connected via I2C-UART bridge SC16IS750
1+
// I2C_Uart/ArduinoBlue
2+
// ftDuino example for ArduinoBlue https://sites.google.com/stonybrook.edu/arduinoble
3+
// The HM10 needs to be connected via I²C using a SC16IS750 to the ftDuino
4+
5+
// This demo needs the ArduinoBlue library. Please install it using the library manager.
26

37
#include "SC16IS750.h"
48
#include <ArduinoBlue.h>
9+
#include <Ftduino.h>
510

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

1419
void setup()
1520
{
21+
ftduino.init();
1622
Serial.begin(9600);
17-
while(!Serial);
1823
i2cuart.begin(9600); //baudrate setting
1924
};
2025

@@ -58,6 +63,14 @@ void loop()
5863
Serial.print("Throttle: "); Serial.print(throttle); Serial.print("\tSteering: "); Serial.println(steering);
5964
prevThrottle = throttle;
6065
prevSteering = steering;
66+
67+
// use throttle to control M1
68+
if(throttle >= 50) // 50 ... 99
69+
ftduino.motor_set(Ftduino::O1, Ftduino::LEFT, Ftduino::MAX * (throttle-50) / 49);
70+
else if(throttle <= 48) // 0 ... 48
71+
ftduino.motor_set(Ftduino::O1, Ftduino::RIGHT, Ftduino::MAX * (48-throttle) / 48);
72+
else // 49
73+
ftduino.motor_set(Ftduino::O1, Ftduino::OFF, Ftduino::MAX);
6174
}
6275

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

0 commit comments

Comments
 (0)