Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <LedControl.h>
- #include <DcsBios.h>
- #include <Servo.h>
- //pin 10 is connected to the DataIn
- //pin 11 is connected to the CLK
- //pin 12 is connected to LOAD
- LedControl lc=LedControl(10,9,8,1);//DIN,CLK,LOAD,# OF IC's
- /**** In most cases, you do not have to change anything below this line ****/
- /* Instantiate a ProtocolParser object to parse the DCS-BIOS export stream */
- DcsBios::ProtocolParser parser;
- void setup() {
- Serial.begin(250000);
- lc.shutdown(0,false); //turn on the display
- lc.setIntensity(0,15);//set the brightness
- lc.clearDisplay(0); //clear rthe display and get ready for new data
- }
- /*
- Your main loop needs to pass data from the DCS-BIOS export
- stream to the parser object you instantiated above.
- It also needs to call DcsBios::PollingInput::pollInputs()
- to detect changes in the state of connected controls and
- pass them on to DCS.
- */
- void loop() {
- // feed incoming data to the parser
- while (Serial.available()) {
- parser.processChar(Serial.read());
- }
- // poll inputs
- DcsBios::PollingInput::pollInputs();
- }
- /*
- You need to define
- void sendDcsBiosMessage(const char* msg, const char* arg)
- so that the string msg, followed by a space, the string arg
- and a newline gets sent to the DCS-BIOS import stream.
- In this example we send it to the serial port, so you need to
- run socat to read the data from the serial port and send it
- over UDP to DCS-BIOS.
- */
- void sendDcsBiosMessage(const char* msg, const char* arg) {
- Serial.write(msg);
- Serial.write(' ');
- Serial.write(arg);
- Serial.write('\n');
- }
- unsigned char max7219_rows[8];
- unsigned char cl_row_map[48] = {
- 0, 0, 0, 0,
- 1, 1, 1, 1,
- 2, 2, 2, 2,
- 3, 3, 3, 3,
- 4, 4, 4, 4,
- 5, 5, 5, 5,
- 0, 0, 0, 0,
- 1, 1, 1, 1,
- 2, 2, 2, 2,
- 3, 3, 3, 3,
- 4, 4, 4, 4,
- 5, 5, 5, 5
- };
- #define SEG_DP (1<<7)
- #define SEG_A (1<<6)
- #define SEG_B (1<<5)
- #define SEG_C (1<<4)
- #define SEG_D (1<<3)
- #define SEG_E (1<<2)
- #define SEG_F (1<<1)
- #define SEG_G (1<<0)
- unsigned char cl_mask_map[48]= {
- SEG_DP, SEG_B, SEG_D, SEG_F,
- SEG_DP, SEG_B, SEG_D, SEG_F,
- SEG_DP, SEG_B, SEG_D, SEG_F,
- SEG_DP, SEG_B, SEG_D, SEG_F,
- SEG_DP, SEG_B, SEG_D, SEG_F,
- SEG_DP, SEG_B, SEG_D, SEG_F,
- SEG_A, SEG_C, SEG_E, SEG_G,
- SEG_A, SEG_C, SEG_E, SEG_G,
- SEG_A, SEG_C, SEG_E, SEG_G,
- SEG_A, SEG_C, SEG_E, SEG_G,
- SEG_A, SEG_C, SEG_E, SEG_G,
- SEG_A, SEG_C, SEG_E, SEG_G
- };
- void updateCautionLights(unsigned int address, unsigned int data) {
- unsigned char row = (address - 0x10d4) * 2;
- unsigned char start_index = row * 4;
- unsigned char column = 0;
- unsigned char i;
- bool is_on;
- for (i=0; i<16; i++) {
- is_on = data & 0x01;
- // set caution light state (row, column, is_on)
- if (is_on) {
- max7219_rows[cl_row_map[start_index+i]] |= cl_mask_map[start_index+i];
- } else {
- max7219_rows[cl_row_map[start_index+i]] &= ~(cl_mask_map[start_index+i]);
- }
- data >>= 1;
- column++;
- if (column == 4) {
- row++;
- column = 0;
- }
- }
- // update MAX7219
- for (i=0; i<8; i++) {
- lc.setRow(0, i, max7219_rows[i]);
- }
- }
- void onDcsBiosWrite(unsigned int address, unsigned int data) {
- if (address >= 0x10d4 && address <= 0x10d8) {
- updateCautionLights(address, data);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement