Версия программы для Arduino под управление через последовательный порт компа.

PHP код:
/*
  Управление радар-детектором Stinger S650 с carpc через интерфейс RR
  
 Питание на нагрузку подается либо при начальной инициализации системы, 
 либо программно (для вкл/выкл нагрузки без снятия питания со всей системы)
 По включению питания формируется импульс сброса самотестирования нагрузки. 
 
 
 The circuit:
 * Оптрон Режима 1  attached from pin 9 to ground 
 * Оптрон Режима 2  attached from pin 11 to ground
 * Оптрон Вкл/Выкл  attached from pin 7 to ground
 * pin 8 attached to pin 11   
 * pin 7 attached to pin 12
  
  ******************
 modified 29.01.2010
  */

// constants won't change. They're used here to 
// set pin numbers:
const int buttonPin1 12;     // Вход с питания
const int buttonPin2 8;     // Вход с формирователя сброса
const int buttonPin7 6;     // Включение/выключение питания
const int ledPin4 =  9;       // Управление 1 режимом
const int ledPin5 =  11;      // Управление 2 режимом/Ипульс сброса теста
const int ledPin2 =  7;      // Включение нагрузки
int val;


// variables will change:
int buttonState 0;         // variable for reading the pushbutton status

void setup() {
  
Serial.begin(115200);              //установка порта 
  // initialize the LED pin as an output:
  
pinMode(ledPin2OUTPUT);
  
pinMode(ledPin4OUTPUT); 
  
pinMode(ledPin5OUTPUT);
    
// initialize the pushbutton pin as an input:
  
pinMode(buttonPin1INPUT);
  
pinMode(buttonPin2INPUT);
  
pinMode(buttonPin7INPUT);

    
// turn LED on:    
    
digitalWrite(ledPin2HIGH); // Первое включение системы
   
  // read the state of the pushbutton value:
  
buttonState digitalRead(buttonPin1);

    
// Если питание подано, формируется импульс сброса с задержкой 2 сек:
  
if (buttonState == HIGH) {     
    
// turn LED on: 
   
delay(2000);                  // пауза на сброс теста for a 2 second 
    
digitalWrite(ledPin5HIGH); // Импульс сброса 1 сек 
   
delay(1000);  
  } 
  else {
  }
}

void loop() {
  
// Если нагрузка уже инициалирована, переход в рабочую программу
  
while (digitalRead(buttonPin1) == HIGH) {
     
work(); 
   }
    
// Если нагрузка не инициалирована, переход в инициализацию
  
while (digitalRead(buttonPin1) == LOW) {
     
initial(); 
   }
}
void initial(){   
  
delay(1000);                  // пауза на включение
   // Выбор режима Вкл/Выкл:
  
if (Serial.available())          //если есть принятый символ, 
  
{
    
val Serial.read();            //  то читаем его и сохраняем в val  
   
  
buttonState digitalRead(buttonPin7);
  
  
// check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  
if (val == 'd') {     
    
// turn LED on:    
    
digitalWrite(ledPin2HIGH); // Включение питания
     

  else {
      }
  
// read the state of the pushbutton value:
  
buttonState digitalRead(buttonPin1);

  
// check if the pushbutton is pressed.
  // Если питание подано, формируется импульс сброса с задержкой 2 сек:
  
if (buttonState == HIGH) {     
    
// turn LED on: 
   
delay(2000);                  // пауза на сброс теста for a 2 second 
    
digitalWrite(ledPin5HIGH); // Импульс сброса 2 сек 
   
delay(1000);  
  } 
  else {
  }

   
// Если импульс сброса сформирован, переход к рабочему циклу
   
while (digitalRead(buttonPin2) == HIGH) {
     
work(); 
   }
}
}

void work(){
  
digitalWrite(ledPin5LOW); // Снятие импульса сброса
  // Выбор режима 1 короткое/длинное нажатие:
  
  
if (Serial.available())          //если есть принятый символ, 
  
{
    
val Serial.read();            //  то читаем его и сохраняем в val 
  
  //buttonState = digitalRead(buttonPin3);
  
  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  
if (val == '1') {     
    
// turn LED on:    
    
digitalWrite(ledPin4HIGH); 
   
delay(1000);                  // Короткое нажатие (Реж.1)
  
digitalWrite(ledPin4LOW);    // set the LED off 
  

  else {
    
// turn LED off:
    
digitalWrite(ledPin4LOW); 
  }
  
//buttonState = digitalRead(buttonPin4);
  
  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  
if (val == '3') {     
    
// turn LED on:    
    
digitalWrite(ledPin4HIGH); 
   
delay(3000);                  // Длинное нажатие (Реж.1)
  
digitalWrite(ledPin4LOW);    // set the LED off 
  

  else {
    
// turn LED off:
    
digitalWrite(ledPin4LOW); 
  }
  
// Выбор режима 2 короткое/длинное нажатие:
  //buttonState = digitalRead(buttonPin5);
  
  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  
if (val == '5') {     
    
// turn LED on:    
    
digitalWrite(ledPin5HIGH); 
   
delay(1000);                  // Короткое нажатие (Реж.2)
  
digitalWrite(ledPin5LOW);    // set the LED off 
  

  else {
    
// turn LED off:
    
digitalWrite(ledPin5LOW); 
}
// read the state of the pushbutton value:
  //buttonState = digitalRead(buttonPin6);
  
  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  
if (val == '7') {     
    
// turn LED on:    
    
digitalWrite(ledPin5HIGH); 
   
delay(3000);                  // Длинное нажатие (Реж.2)
  
digitalWrite(ledPin5LOW);    // set the LED off 
  

  else {
    
// turn LED off:
    
digitalWrite(ledPin5LOW); 
  }
  
  
// Включение/выключение питания:
  //buttonState = digitalRead(buttonPin7);
  
  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  
if (val == 'd') {     
    
// turn LED on:    
    
digitalWrite(ledPin2LOW); 
   
delay(1000);                  // 
  
digitalWrite(ledPin2LOW);    // set the LED off 
  

  else {
  }
  }

В данной версии еще не реализовано управление громкостью динамика.

Мои благодарности Chip`у и AlexNS за неоценимую помощь, оказанную при написании проги для фронт-энда (тема об этом)