hello I'm Joel aka BatDog1981
I've been teaching myself for the past few years and i have a lot of projects I've completed but since this is controlling my HoverBot (4x4 hoverboard motors and Odrive v3.6) ,using delay isn't available since i every millis second is needed I'm far from finished but what I'm trying to do is is when pushing ch1 forward i want to display it on 16x2 LCD. but i want to display forward / reverse. but if i hit ch1 high
i want it to display for as long as im holding ch1 foward it will display either until i let go and ch goes to idle. or if im holding forward and another ch changes state then the latest command overwrites ch message LCD displays newest action but wont display ch1 forward unless ch1 goes back to idle then ch1 will be displayed once again. sorry so long.
#include <IBusBM.h>
IBusBM IBus;
///////////////////RELAY////////////////////////////////////
int relay_1 = 3;
int relay_2 = 4;
int relay_3 = 5;
int relay_4 = 6;
/////////////////millis////////////////////////////////////////////
unsigned long startMillis;
unsigned long currentMillis;
unsigned long period = 500;
//////////////LCD////////////////////////////////////////////
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2); // set the LCD address to 0x27 for a 16 chars and 2 line display
//////////////////////////////////////////////////////////////
void setup() {
// initialize serial port for debug
Serial.begin(115200);
////////////////////////////RELAY///////////////////////////////////////////////
pinMode(relay_1, OUTPUT);
pinMode(relay_2, OUTPUT);
pinMode(relay_3, OUTPUT);
pinMode(relay_4, OUTPUT);
startMillis = millis();
///////////////////////////////////////////////////////////////////////////////////
IBus.begin(Serial1);
lcd.init();
lcd.clear();
lcd.backlight();
lcd.setCursor(2, 0); //Set cursor to character 2 on line 0
lcd.print("HoverBot 1.0");
lcd.setCursor(2, 1); //Move cursor to character 2 on line 1
lcd.print("by: Joel Olsen");
Serial.println("Running Ibus encryption");
// adding 2 sensors
IBus.addSensor(IBUSS_RPM);
IBus.addSensor(IBUSS_TEMP);
}
#define TEMPBASE 400 // base value for 0'C
// sensor values
uint16_t speed = 0;
uint16_t temp = TEMPBASE + 200; // start at 20'C
//////////////////////////////void updateDisplay///////////////////////////////////////
void BaseDisplay() {
//////////////////////////////millis////////////////////////////////////////////////
currentMillis = millis();
if (currentMillis - startMillis >= period)
//////////////////////////////////////////////////////////////////////////////////////
lcd.init();
lcd.clear();
lcd.clear();
lcd.backlight();
lcd.setCursor(2, 0);
lcd.print("HoverBot 1.0");
lcd.setCursor(2, 1);
lcd.print("IDLE");
///////figure out if need to have all channel values to be nuetural
}
void realay_1_off(){
currentMillis = millis();
if (currentMillis - startMillis >= period)
//////////////////////////////////////////////////////////////////////////////////////
lcd.init();
lcd.clear();
lcd.clear();
lcd.backlight();
lcd.setCursor(2, 0);
lcd.print("HoverBot 1.0");
lcd.setCursor(2, 1);
lcd.print("IDLE");
}
void relay_1_on() {
//////////////////////////////millis////////////////////////////////////////////////
currentMillis = millis();
if (currentMillis - startMillis >= period)
//////////////////////////////////////////////////////////////////////////////////////
lcd.init();
lcd.clear();
lcd.clear();
lcd.backlight();
lcd.setCursor(2, 0);
lcd.print("HoverBot 1.0");
lcd.setCursor(2, 1);
lcd.print("relay 1 ON");
}
}
void noController() {
//////////////////////////////millis////////////////////////////////////////////////
currentMillis = millis();
if (currentMillis - startMillis >= period)
//////////////////////////////////////////////////////////////////////////////////////
lcd.clear();
lcd.backlight();
lcd.setCursor(2, 0);
lcd.print("HoverBot 1.0");
lcd.setCursor(2, 1);
lcd.print("Connect Controller");
}
void updateDisplay2() {
//////////////////////////////millis////////////////////////////////////////////////
currentMillis = millis();
if (currentMillis - startMillis >= period)
//////////////////////////////////////////////////////////////////////////////////////
lcd.clear();
lcd.backlight();
lcd.setCursor(2, 0); //Set cursor to character 2 on line 0
lcd.print("HoverBot 1.0");
lcd.setCursor(2, 1); //Set cursor to character 2 on line 0
lcd.print("ch2 LOW");
}
void updateDisplay3high() {
//////////////////////////////millis////////////////////////////////////////////////
currentMillis = millis();
if (currentMillis - startMillis >= period) {
//////////////////////////////////////////////////////////////////////////////////////
lcd.clear();
lcd.backlight();
lcd.setCursor(2, 0); //Set cursor to character 2 on line 0
lcd.print("HoverBot 1.0");
lcd.setCursor(2, 1); //Set cursor to character 2 on line 0
lcd.print("ch3 HIGH");
}
}
void updateDisplay3low() {
//////////////////////////////millis////////////////////////////////////////////////
currentMillis = millis();
if (currentMillis - startMillis >= period) {
//////////////////////////////////////////////////////////////////////////////////////
lcd.clear();
lcd.backlight();
lcd.setCursor(2, 0); //Set cursor to character 2 on line 0
lcd.print("HoverBot 1.0");
lcd.setCursor(2, 1); //Set cursor to character 2 on line 0
lcd.print("ch3 LOW");
}
}
///////////////////////////////////////////////////////////////////////////////////
void loop() {
///////////////millis/////////////////////////////////////////////
// currentMillis = millis();
//if (currentMillis - startMillis >= period)
//////////////////////////////////////////////////////////////////
// show first 10 servo channels
for (int i = 0; i < 10 ; i++) {
Serial.print(IBus.readChannel(i));
Serial.print(" ");
}
Serial.print("Cnt=");
Serial.print(IBus.cnt_rec);
Serial.print(" POLL=");
Serial.print(IBus.cnt_poll);
Serial.print(" Sensor=");
Serial.println(IBus.cnt_sensor);
////ADDED////
//////////////ch1 l 51148 mid 50842 50152///250 diff///////////////////////
if (IBus.readChannel(0) <= 50) {
noController();
}
if (IBus.readChannel(0) <= 50402) {
int ch1 = LOW;
// updateDisplay1(); /// Recalls Void updateDisplay1() {
Serial.print("ch1 LOW");
Serial.println(" ");
}
if (IBus.readChannel(0) >= 50403 && (IBus.readChannel(0) <= 50898)) {
Serial.print("ch1 IDLE");
Serial.println(" ");
}
if (IBus.readChannel(0) >= 50899) {
int ch1 = HIGH ;
//updateDisplay1(); /// Recalls Void updateDisplay1() {
Serial.print("ch1 HIGH");
Serial.println(" ");
}
//ch2///////////ch2 55245 54738 54249////////////////////////////////////////////
if (IBus.readChannel(1) <= 54499) {
// updateDisplay2();
Serial.print("ch2 LOW");
Serial.println(" ");
}
if (IBus.readChannel(1) <= 54995 && (IBus.readChannel(1) >= 54500)) {
//updateDisplay2();
Serial.print("ch2 IDLE");
Serial.println(" ");
}
if (IBus.readChannel(1) >= 54996) {
// updateDisplay2();
Serial.print("ch2 HIGH");
Serial.println(" ");
}
//ch3////////////ch3 22480 21949 21487////////////////////////////////////////
if (IBus.readChannel(2) <= 21737) {
updateDisplay3low();
Serial.print("ch3 LOW");
Serial.println(" ");
}
else {
BaseDisplay();
}
if (IBus.readChannel(2) <= 22229 && (IBus.readChannel(2) >= 21738)) {
Serial.print("ch3 IDLE");
Serial.println(" ");
}
if (IBus.readChannel(2) >= 22230) {
updateDisplay3high();
Serial.print("ch3 HIGH");
Serial.println(" ");
}
else {
BaseDisplay();
}
//ch4/////////////ch4 50152 50672 51151//////////////////////////////////////
if (IBus.readChannel(3) <= 50402) {
Serial.print("ch4 LOW");
Serial.println(" ");
}
if (IBus.readChannel(3) <= 50900 && (IBus.readChannel(3) >= 50403)) {
Serial.print("ch4 IDLE");
Serial.println(" ");
}
if (IBus.readChannel(3) >= 50901) {
Serial.print("ch4 HIGH");
Serial.println(" ");
}
//ch5//////////////cd5 55248 54770 54248/////////////////////////////////////////
if (IBus.readChannel(4) <= 54490) {
Serial.print("ch5 LOW");
Serial.println(" ");
}
if (IBus.readChannel(4) <= 54997 && (IBus.readChannel(4) >= 54491)) {
//updateDisplay2();
Serial.print("ch5 IDLE");
Serial.println(" ");
}
if (IBus.readChannel(4) >= 54998) {
// updateDisplay2();
Serial.print("ch5 HIGH");
Serial.println(" ");
}
//ch6/////////////ch6 22480 21993 21480///////////////////////////////////////////////
if (IBus.readChannel(5) <= 21730) {
Serial.print("ch6 LOW");
Serial.println(" ");
}
if (IBus.readChannel(5) <= 22229 && (IBus.readChannel(5) >= 21731)) {
//updateDisplay2();
Serial.print("ch6 IDLE");
Serial.println(" ");
}
if (IBus.readChannel(5) >= 22230) {
Serial.print("ch6 HIGH");
Serial.println(" ");
}
//ch7///SWITCH//////ch7 500152 51152//////////////////////////////////////////////
if (IBus.readChannel(6) <= 50652) {
relay_1_on();
digitalWrite(relay_1, LOW);
Serial.print("ch7 OFF");
Serial.println(" ");
}
if (IBus.readChannel(6) >= 50653) {
relay_1_off();
digitalWrite(relay_1, HIGH);
Serial.print("ch7 ON");
Serial.println(" ");
}
//ch8/////SWITCH///////////ch8 55248 54248/////////////////////////////////////////
if (IBus.readChannel(7) <= 54748) {
digitalWrite(relay_2, LOW);
Serial.print("ch8 OFF");
Serial.println(" ");
}
if (IBus.readChannel(7) >= 54749) {
digitalWrite(relay_2, HIGH);
Serial.print("ch8 ON");
Serial.println(" ");
}
//ch9////3-WAY SWITCH/////////ch9 22480 21980 21480///////////////////////////////////////////
if (IBus.readChannel(8) <= 21730) {
Serial.print("ch9 pos1");
Serial.println(" ");
}
else if (IBus.readChannel(8) <= 22229 && (IBus.readChannel(8) >= 21731)) {
Serial.print("ch9 pos2");
Serial.println(" ");
}
if (IBus.readChannel(8) >= 22230) {
Serial.print("ch9 pos3");
Serial.println(" ");
}
//ch10////////////////ch10 51152 50152 ////////////////////////////////////
if (IBus.readChannel(9) <= 50652) {
digitalWrite(relay_4, LOW);
Serial.print("ch10 OFF");
Serial.println(" ");
}
if (IBus.readChannel(9) >= 50653) {
digitalWrite(relay_4, HIGH);
Serial.print("ch10 ON");
Serial.println(" ");
}
//////////////////////////////////////////////////////////////////////////////
IBus.setSensorMeasurement(1, speed);
speed += 10;
// increase motor speed by 10 RPM
IBus.setSensorMeasurement(2, temp++); // increase temperature by 0.1 'C every loop
delay(500);
}
}