From 8f689913586deda8c3c5292af137e60a02e23f41 Mon Sep 17 00:00:00 2001 From: harbaum Date: Mon, 13 Jul 2020 09:21:54 +0200 Subject: [PATCH] Update ArduinoBlue examples --- .../CounterPort/ArduinoBlue/ArduinoBlue.ino | 18 ++++++++++++++++-- .../I2C_Uart/ArduinoBlue/ArduinoBlue.ino | 17 +++++++++++++++-- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/ftduino/libraries/Ftduino/examples/Bluetooth/CounterPort/ArduinoBlue/ArduinoBlue.ino b/ftduino/libraries/Ftduino/examples/Bluetooth/CounterPort/ArduinoBlue/ArduinoBlue.ino index 3dec506..e318fbf 100644 --- a/ftduino/libraries/Ftduino/examples/Bluetooth/CounterPort/ArduinoBlue/ArduinoBlue.ino +++ b/ftduino/libraries/Ftduino/examples/Bluetooth/CounterPort/ArduinoBlue/ArduinoBlue.ino @@ -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 phone(Serial1); @@ -12,9 +19,8 @@ int throttle, steering, sliderVal, button, sliderId; void setup() { + ftduino.init(); Serial.begin(9600); - while(!Serial); - Serial1.begin(9600); }; @@ -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 diff --git a/ftduino/libraries/Ftduino/examples/Bluetooth/I2C_Uart/ArduinoBlue/ArduinoBlue.ino b/ftduino/libraries/Ftduino/examples/Bluetooth/I2C_Uart/ArduinoBlue/ArduinoBlue.ino index 01e5f0f..0366ecd 100644 --- a/ftduino/libraries/Ftduino/examples/Bluetooth/I2C_Uart/ArduinoBlue/ArduinoBlue.ino +++ b/ftduino/libraries/Ftduino/examples/Bluetooth/I2C_Uart/ArduinoBlue/ArduinoBlue.ino @@ -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 +#include SC16IS750 i2cuart = SC16IS750(SC16IS750_PROTOCOL_I2C,SC16IS750_ADDRESS_BB); ArduinoBlue phone(i2cuart); @@ -13,8 +18,8 @@ int throttle, steering, sliderVal, button, sliderId; void setup() { + ftduino.init(); Serial.begin(9600); - while(!Serial); i2cuart.begin(9600); //baudrate setting }; @@ -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