Skip to content

Instantly share code, notes, and snippets.

@PeterJohnson
Created February 15, 2020 06:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PeterJohnson/0a6ccbc6ba24c225a6db44e8372493f0 to your computer and use it in GitHub Desktop.
Save PeterJohnson/0a6ccbc6ba24c225a6db44e8372493f0 to your computer and use it in GitHub Desktop.
Thanksgiving LED
#include <cstring>
#include <vector>
#include <frc/AddressableLED.h>
#include <frc/TimedRobot.h>
static const char* msg[8] = {
"* * ***** ***** ***** * * ***** * * ***** * * * * ***** ***** ***** * * ***** * * ***** * 2 3 ",
"* * * * * * * * * * * * * * * * * * * * * * * * * * * * * 2 3 ",
"* * * * * * * * * * * * * * * ** * * * * * * * * * ** * * * 2 3 ",
"***** ***** ***** ***** ***** * ***** ***** * * * ** ***** * ** * * * * * * * * ** * 2 3 ",
"* * * * * * * * * * * * * ** * * * * * * * * * * ** * * * 2 3 ",
"* * * * * * * * * * * * * * * * * * * * * * * * * * * ",
"* * * * * * * * * * * * * * * * ***** ***** ***** * ***** * * ***** * 2 3 ",
" "
};
class MyRobot : public frc::TimedRobot {
frc::AddressableLED led{0};
std::vector<frc::AddressableLED::LEDData> ledData =
std::vector<frc::AddressableLED::LEDData>(8*32);
int count = 0;
int colstart = 0;
int msglen = strlen(msg[0]);
/**
* This function is run when the robot is first started up and should be
* used for any initialization code.
*/
void RobotInit() override {
led.SetLength(8*32);
led.Start();
}
/**
* This function is called periodically during all modes
*/
void RobotPeriodic() override {
++count;
if (count > 3) {
count = 0;
for (int row=0; row<32; ++row) {
for (int col=0; col<8; ++col) {
frc::AddressableLED::LEDData color(0, 0, 0);
//ledData[row*32 + col] = color;
if (msg[col][(colstart + row) % msglen] == '*')
color = frc::AddressableLED::LEDData(255, 0, 0);
else if (msg[col][(colstart + row) % msglen] == '2')
color = frc::AddressableLED::LEDData(0, 255, 0);
else if (msg[col][(colstart + row) % msglen] == '3')
color = frc::AddressableLED::LEDData(0, 0, 255);
ledData[row*8 + (((row & 1) == 1) ? (7-col) : col)] = color;
}
}
//ledData[colstart] = frc::AddressableLED::LEDData(255, 0, 0);
led.SetData(ledData);
++colstart;
//if (colstart >= 8*32) colstart = 0;
if (colstart >= msglen) colstart = 0;
}
}
};
int main() { return frc::StartRobot<MyRobot>(); }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment