А вот за прогу респект! На тебе еще из той же серии. Программа предназначена для RCX, она превращает P-брик в пульт управления Спайбота. Тем самым демонстрируется возможный вариант интеграции различных процессорных блоков Лего. Управление осуществляется нажатием на три сенсора касания RCX. Второй и третий сенсор включают двигатели Спайбота, а сенсор номер один при нажатии включает реверс для двигателей спайбота. #define EVENT_1 0 #define EVENT_2 1 #define EVENT_3 2 #define MANAS_1 5 #define MANAS_2 6 #define MANAS_3 7 #define EM_FLOAT 0 #define EM_OFF 8 #define EM_FWD 7 #define EM_REV 15 task main(){ int motor_1, motor_2; SetSerialComm(SERIAL_COMM_4800|SERIAL_COMM_DUTY25|SERIAL_COMM_76KHZ); SetSerialPacket(SERIAL_PACKET_DEFAULT); SetSensor(SENSOR_1, SENSOR_TOUCH); SetSensor(SENSOR_2, SENSOR_TOUCH); SetSensor(SENSOR_3, SENSOR_TOUCH); SetTxPower(TX_POWER_HI); while (true){ if(SensorValueBool(0)==0 && SensorValueBool(1)==0 && SensorValueBool(2)==0){ motor_1=EM_OFF; motor_2=EM_OFF; } if(SensorValueBool(0)==1 && SensorValueBool(1)==1 && SensorValueBool(2)==1){ motor_1=EM_REV; motor_2=EM_REV; } if(SensorValueBool(0)==0 && SensorValueBool(1)==1 && SensorValueBool(2)==1){ motor_1=EM_FWD; motor_2=EM_FWD; } if(SensorValueBool(0)==0 && SensorValueBool(1)==1 && SensorValueBool(2)==0){ motor_1=EM_FWD; motor_2=EM_REV; } if(SensorValueBool(0)==0 && SensorValueBool(1)==0 && SensorValueBool(2)==1){ motor_2=EM_FWD; motor_1=EM_REV; } if(SensorValueBool(0)==1 && SensorValueBool(1)==1 && SensorValueBool(2)==0){ motor_2=EM_FWD; motor_1=EM_REV; } if(SensorValueBool(0)==1 && SensorValueBool(1)==0 && SensorValueBool(2)==1){ motor_1=EM_FWD; motor_2=EM_REV; } // Send IR commands for left/right motor packet // format: 01CCRRRR LLLLSSSS // C = channel number (1 to 3) // R = right motor // L = left motor // S = checksum SetSerialData(0,MANAS_2*0x10+motor_1); SetSerialData(1,motor_2*0x10+0x10-((MANAS_2+motor_1+motor_2)&0xf)); SendSerial(0,2); } } |