Thursday, December 11, 2014

Pretty close to the final code for the LED display!

This is an adaptation of the code that was posted on the blog earlier, that has been made to work for our setup. it should work for us, but it hasn't been tested yet and will need some minor tweaks.

/*
Team Frequency
Design Lab 1 Final
POV Display final Code
12/12/2014

This code is designed to illuminate the LEDs on an arduino breadboard mounted on a rotating disc spinning at a known RPM. Ideally, the
only variable that needs to be modified is the value of period, which represents the period of rotation of the disc. The delay values may
also need to be modified slightly, or alternatively, the n value and corrosponding length of the lines of text in the message array may be
increased to provide a longer delay if the message is repeating itself or illegibly compact. Requires a separate arduino running the motor
attachment.

*/

//-----------------------Variable Declaration----------------------------------------------------
long period = 400;
int ledPins[] = {12, 11, 10, 9, 8, 7};
int n = 128;
char *message[6] = {
"11111111110001111111111000011111111100011111111110000000000000000000000000000000000000000000000000000000000000000000000000000000",
"00001100000001100000000000111000000000000001100000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"00001100000001111111000000011111111000000001100000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"00001100000001100000000000000000011100000001100000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"00001100000001111111111000111111111000000001100000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
};


/*
//This is an attempt to create the team name on the display. Will be completed if the display proves functional.

char *messageB[6] = {
"1111111111000111111111100000011110000001110000001110000000000000000111111111100011111110000001111111111000011111111000011000000001100011111111110001110000011000000111111100011100001110000000000",
"000011000000011000000000000011001100000111110011111000000000000000011000000000001100001100
"000011000000011111110000000110000110000110011110011000000000000000011111110000001100011000
"000011000000011000000000001111111111000110001100011000000000000000011000000000001111110000
"000011000000011111111110001100000011000110000000011000000000000000011000000000001100011000
*/

//--------------------------------Setup Function---------------------------------------
void setup()
{
 for (int led = 0; led < 6; led ++)
 {
   pinMode(ledPins[led], OUTPUT);
 }
}

//--------------------------------Main Loop--------------------------------------------

void loop()
{
  for (int col = 0; col < n; col++)                // This code divides the char array message into columns using nested for-loops.
  {
    for (int row = 0; row < 6; row++)              // The LEDs in each column light for 1/1000th of the period, shown by the delayMicrosecond(period) function, before turning off.
    {
      if(message[5-row][col] != 0){
        setLed(row);
      }
    }
    delayMicroseconds(period);                     // The delay values may need to be adjusted if the timing of the system is too far off. Microseconds may be too short to effectively work.
    allOff();
    delayMicroseconds(period / 16);
  }
}

//-----------------------------Additional Functions-----------------------------------

void setLed(int led)
{
 digitalWrite(ledPins[led], HIGH);                  // Turns on the LED chosen by the main loop.

}

void allOff()
{
   for (int led = 0; led < 6; led ++)                // Resets all LEDs to the LOW position after the delay.
 {
    digitalWrite(ledPins[led], LOW);
 }
}

No comments:

Post a Comment