This code controls four light bars mounted on my highschool FRC team's (1732 Hilltoppers) competition robot. At the system's heart is an ATMEGA328p (Arduino Nano). WS2812B LED strips were soldered together in four chains of five.
Control commands came from the robot RoboRIO digital IO pins (DIO 0, 1, and 2 + GND). Three pins were used for a total of 8 (2^3) different lighting sequences.
- Arduino IDE (https://www.arduino.cc/en/software)
- Double-click on the RGBMode.ino file (inside the RGBMode folder) to open it in the Arduino IDE.
Command | Description | Reasoning |
---|---|---|
0 | These RGB lights are bright, power-hungry, and run hot. When nothing is going on, turn them off. | |
1 | An alert to the drive team that we are A) In Autonomous Mode. B) The robot has picked up 1 ball. | |
2 | An alert to the drive team that we are A) In Autonomous Mode. B) The robot has picked up 2 balls. | |
3 | An alert to the drive team that we are A) In TeleOp Mode. B) The robot has picked up 1 ball. | |
4 | An alert to the drive team that we are A) In TeleOp Mode. B) The robot has picked up 2 balls. | |
5 | The robot is autonomously aligning to shoot a ball and spinning up the shooter flywheel. Don't Touch! | |
6 | The robot is aligned and autonomously shooting. Don't Touch! | |
7 | When the robot is idle, run a breathing animation that switches between blue and gold (our school colors). |
- Important - Configure for the board. From the Menu, select Tools / Board: / Arduino AVR Boards / Arduino Nano
- Load Adafruit's NeoPixel Library (if you haven't already) - From the Menu, select Sketch / Include Library / Manage Libraries... Search for "neopixel" and install the Adafruit NeoPixel library.
- You can test if the sketch compiles by clicking the check mark button in the upper left corner of the IDE.
- Make sure you have the right board selected: Tools / Board: / Arduino AVR Boards / Arduino Nano
- Select the correct COM/Serial port. You can configure this by selecting: Tools / Port / this part will be different, but should either start with /tty or COM followed by a number
- To flash, make sure your board is selected and connected, then click the arrow button in the upper left corner of the IDE.
- If issues arise when flashing, check out the Arduino Docs: https://docs.arduino.cc/. They have great resources and tutorials for flashing to every board on the front page (as of Oct. 2023)!
- Also, the cable you use oftentimes is the issue when flashing. Make sure the USB cable isn't just a power cable!!
Arduino .ino files are based on a simplified version of C (though you can still add external C/C++ libraries using #include). It is fairly similar to Java (yay curly brackets!), but memory management is very different. Also, memory (RAM) on the Arduino is extremely limited (you only have 2kB). When in doubt, copy/paste, then modify existing code or look at the Arduino Docs: https://docs.arduino.cc/.