Created
February 15, 2020 06:44
-
-
Save PeterJohnson/0a6ccbc6ba24c225a6db44e8372493f0 to your computer and use it in GitHub Desktop.
Thanksgiving LED
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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