i made the few changes that you recommended Pete and re-uploaded the code to the device.
It does seem to now be working, at least interacting. Thank you. It is not working exactly as I expect, but I am MUCH farther along than I was before. The reverse doesn’t seem to be working, well, really, the right motor doesn’t seem to be reacting to changes in the joystick. The right motor is just continuously running in the same direction, while the left motor changes based on the joystick changes. Is there something related to this:
that needs to be addressed or added or calculated?
I’d guess that the best approach is to see what values are coming from the joystick widget and if necessary add a C++ map command into your sketch to re-map these values to the range that you need.
Amazing the progress than can be made when you share your existing code . . . and listen to people who are trying to help . . . good luck, hopefully a lesson learnt.
I was going to say something about being so smug, but I realized that nothing good comes from that sort of talk.
The issue I have now is that the reaction and interaction of the Android to the 8266 is so slow that it’s practically not worth having gone through the pain of figuring out the new Blynk app.
I’m trying to run just two motors (as the code suggests) and they are fine once they start moving, but as soon as you want to do anything other than go straight and move the joystick even a little bit, the motors stop, have to re-acquire, and then start moving in the new direction. That whole process takes 3-7 seconds. Not very interesting or fun for a remote control vehicle. Sadly, the original app was easier to understand and use and this process worked flawlessly.
@John93 gave you a link to the “keep your void loop clean” article, and that’s one of the things you need to take onboard.
From what I can see, none of the code needs to be in your void loop, except Blynk.run() because the only time that the values change that influence the if statements in your void loop is when your joystick moves.
You could put this code in your BLYNK_WRITE() function, but it would probably be better in its own function that is called from the BLYNK_WRITE()
Also, these consecutive if statements need to be processed each time. I’m sure this code could be streamlined with the addition of some return commands if there’s a situation where one if statement evaluates as true and this negates the need for the following if statements to be evaluated.
In addition, serial print statements take time to process. Whilst they are useful for debugging, they should probably be removed, or better turned off, in your final version of the sketch.
The neat way to do this is to have a #define debug_output command and your serial print commands inside a #ifdef and #endif` block like this…
I just commented out all of the serial.print lines and the interaction is actually very good.
Additionally, I’m not sure how to move some of the items in the void loop to clean it up as you and @John93 suggest. Is it suggested that I create another function to call this code?
No, another function to hold this code, then you call this function when your joystick value changes.
Your joystick changes trigger one of your BLYNK_WRITE() functions, so you call the new function from that BLYNK_WRITE() function.
//Everytime the joystick changes
BLYNK_WRITE(V0)
{
//Get the Blynk joystick values
Joystick_x = param[0].asInt();
Joystick_y = param[1].asInt();
process_joystick(); //call the new function
}
void process_joystick()
{
// put your map commands in here
// along with the joystick/motor control code that is in your void loop
}