Introduction
By this point much experience and understanding had been gained in the use of libraries and their ability to simplify what is going on in the main program. It was decided that a library will be written to support the lighting system as a whole. This will cut down on code repetition and allow for quicker implementation of new features and tweaks. Code written to date has been modified and transferred to the library.
The Library so far
The current status of the code allows for functions to be sent via wireless to the module and for these to be acted upon. Although the fade function has yet to be written the system is responding to simple commands and LED outputs are being manipulated wirelessly. The Driver class in the Library currently contains the following working functions:
“Initialize” – This function initializes and configures the wireless module and the LED driver IC. It also begins a serial connection at 57600 baud and displays version number on the LCD screen.
“checkRadio” – This function checks the radio module to see if any commands have been received and are in the buffer. If there is a command available it will move it to the “received command” (recCMD) variable for processing and return a “1”. If no command is available it will return a “0”.
“processCmd” – This function should be run directly after checkRadio returns a “1”. It reads the “received command” variable and run the correct function based on its content.
The following functions are currently available commands which the driver unit will respond to, the data for each command is contained within the received command:
“setOut” – this function sets the selected channel to the defined value. It does this by modifying the “nextChanVal” array.
“setAll” – This function sets all channels on the selected bar to the defined value. It does this by modifying the “nextChanVal” array.
“outUpdate” – This is called to push the “nextChanVal” array out to the LED lights and at the same time copy it to the “currentChanVal” array.
The fade command will be replacing the “setOut” command which was created for testing purposes. For instant changes the fade time for the fade command will be set to “0”. If a time is given for the fade, the function will take the difference of the current and next values for each colour to create a step value per time segment which will then be run through using a loop.
Some direct access commands will also be created which ignore the use of the current and next arrays for lower latency control. Any direct access commands will be prefixed with a “D”.
Code Excerpts
Some Code for the relevant functions:
ClightiveDrvr::initialize()
void ClightiveDrvr::initialize() //Initialize Driver { rf12_config(); //Call ROM settings for wireless module Tlc.init(); //Initialize TLC5940 with its Lib Serial.begin(57600); Serial.print("\nLED DRIVER FIRMWARE V0.0\n"); for( uint8_t chan = 0 ; chan < 16 ; chan++ ){ Tlc.set( chan, 4095 ); currentval[chan] = 4095; } Tlc.update(); lcd.begin(16, 2); // set up the LCD's number of columns and rows //Display GRAPHIC INITIALIZATION SEQUENCE -------------------- lcd.print("LED DRIVER V0.0"); delay(2000); lcd.clear(); lcd.home(); lcd.print("Louis Christodoulou"); delay(1000); for( uint8_t x = 1 ; x < 21 ; x++){ lcd.scrollDisplayLeft(); delay(500/x); } lcd.clear(); lcd.home(); lcd.print("Waiting..."); //END INITIALIZATION -------------------------------- }
ClightiveDrvr::checkRadio()
uint8_t ClightiveDrvr::checkRadio() //Check Radio for any recieved commands, returns 1 for command waiting { if (rf12_recvDone() && rf12_crc == 0) { lcd.setCursor(15, 0); lcd.print("<"); for (byte i = 0; i < rf12_len; ++i) { recCmd[i] = rf12_data[i]; //Serial.print("\n"); //Serial.print(recCmd[i], DEC); Serial.print(rf12_data[i]); } delay(200); // otherwise LCD symbol isn't visible lcd.setCursor(15, 0); lcd.print(" "); return 1; } return 0; }
ClightiveDrvr::processCmd()
void ClightiveDrvr::processCmd() { switch(recCmd[0]) { case CMD_BLACKOUT: break; case CMD_FADE: setFade(); break; case CMD_OUTUPDATE: outUpdate(); break; } // end switch }
As more functions are written this post will be updated.
Leave A Comment