///////////////////////////////////////////////////////////////////// // mavjuz WinLpt 0.2.9 // Sketch for Arduino MEGA // The device receives commands (bytes) from the computer // and controls the discrete outputs (for example, LEDs) // // Protocol: // 0 - Turn off the output signal // 255 - Turn on the output signal // 1 - Reset the current channel number on the 0 // Any other commands - Ignore // // WinLpt settings, for the output plugin Generic Serial output: // Baud Rate: 9600, 19200, 38400, 57600, 115200 // Header: 1 // Footer: leave blank // Send on stop (full packet): 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 // Data bytes count: any from 1 to 32 // ///////////////////////////////////////////////////////////////////// // Program code ///////////////////////////////////////////////////////////////////// // * Number of outputs for control (for MEGA from 1 to 32 items) const int channels[] = {22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53}; // * Baud rate of data exchange with a computer const int baudrate = 9600; // 9600, 19200, 38400, 57600, 115200 // Number of control channels const int numChannels = sizeof(channels); // The channel number for which the command will be applied int curChannel = 0; // The setup() function is executed 1 time when the controller is started void setup() { // Starting and setting the speed for receiving data via USB-COM Serial.begin(baudrate); // Configuring the controller output signal for(int i = 0; i < numChannels; i++) { // Output Mode pinMode(channels[i], OUTPUT); // Turning off the output signal digitalWrite(channels[i], LOW); } } // The loop() function is executed cyclically void loop() { // y will be equal to the number of commands (bytes) received from the computer int y = Serial.available(); for (int i = 0; i < y; i++) // Processing cycle of incoming commands { int inc = Serial.read(); // Reading data if (inc == 1) // If receive a command to reset { curChannel = 0; // Resetting the current channel number to 0 continue; // Continue processing cycle } if (curChannel < numChannels) // If the channel number is less than the number of channels { digitalWrite(channels[curChannel], !!inc); // Make output signal curChannel++; // Go to the next channel } } }