Hello forum!
I programmed some code to display a waving Ukrainian flag on the V5 brain screen before states. We ran it at states, and I have since built it out into a far more functional class. I thought that there would be some people here on the forum that would appreciate a release of it. Sorry I didn’t get around to releasing it earlier.
I wrote this code for VEXcode Pro V5, mostly because that is what our team uses for programming. The GIFs in this are a little squished, but bear with me.
Waving Ukrainian Flag Code
For the Vex V5 Brain Screen using VEXCode Pro V5
I’m including 2 different files for everyone to play with.
Header File
The header file flagLib.h includes the complete class, along with some explanatory comments. Merely add this to your include folder in VexCode Pro V5, and then #include it into whatever files you wish to use it in.flagLibHeader.zip (5.0 KB)
Demo Project
The demo project displays a flag going up a flagpole on the Brain Screen. It’s something cool that I whipped up when I had some spare time.
flagLibDemo.zip (89.3 KB)
For those who have not programmed anything to display on their brain screen, it is pretty simple to use this! I’ll even include plenty of code to get you started! You can replace your main function in the competition template with this (if you have any stuff like bstopAllTasksBetweenModes then you should put that in):
flag ukraine(60, 25, 200, 10, 3.14 / 8, 10, true, true);
int main() {
// Set up callbacks for autonomous and driver control periods.
Competition.autonomous(autonomous);
Competition.drivercontrol(usercontrol);
// Run the pre-autonomous function.
pre_auton();
// Prevent main from exiting with an infinite loop.
while (true) {
// Clear the screen. Sort of critical.
Brain.Screen.clearScreen();
ukraine.update(Brain);
Brain.Screen.render();
wait(100, msec);
}
}
This will get the whole job done in a jiffy!
For those who have something that they are displaying on their brain screen, the task becomes a bit more tricky to handle, I’ll admit. But it is still pretty easy to do (especially since I am going to tell you exactly how to do it).
What our team does is since we have an auton selector on the brain screen, along with an indicator for when the inertial has calibrated, we have a boolean called pre_autonRan.
flag ukraine(60, 25, 200, 10, 3.14 / 8, 10, true, true);
int main() {
// Set up callbacks for autonomous and driver control periods.
Competition.autonomous(autonomous);
Competition.drivercontrol(usercontrol);
Competition.bStopAllTasksBetweenModes = true;
// Run the pre-autonomous function.
pre_auton();
// Prevent main from exiting with an infinite loop.
while (true) {
if (pre_autonRan) {
// Clear the screen. Sort of critical.
Brain.Screen.clearScreen();
ukraine.update(Brain);
Brain.Screen.render();
}
wait(100, msec);
}
}
Main only runs the flag code when the pre_autonRan is set to true. Simple, yet effective. The code starts with pre_autonRan as false. At the end of pre_auton, we set the boolean to true and then the flag appears on the screen. We also set pre_autonRan to be true at the start of driver control and auton. This allows us to control when the flag is on the screen with great precision. So it is definitely possible to use the screen and still display the flag. Here is what our code does:
The simplest constructor for a flag asks for 4 values, which are all pretty simple. X position, Y position, height (since flag is 2:3 it is essentially size), and whether to draw a flagpole next to the flag. This will create the most simple flag, but depending on the values it may not look very good. I’ll let you look at the comments to check out the rest of the constructors.