Arduino DLP emulation
Posted: Sat Sep 11, 2021 10:07 am
Cannot find here I put the original code, so pasting here:
Create a new Ardino project, and then paste this code into it. Compile and then A0-A5 are your inputs (A0 = AFR, A1-A5 = AUX1-5)
Create a new Ardino project, and then paste this code into it. Compile and then A0-A5 are your inputs (A0 = AFR, A1-A5 = AUX1-5)
Code: Select all
/* Arduino One - DLP emulation */
const int DLP_CMD_DIGITAL_IN_CH1 = 0x41;
const int DLP_CMD_DIGITAL_IN_CH2 = 0x53;
const int DLP_CMD_DIGITAL_IN_CH3 = 0x44;
const int DLP_CMD_DIGITAL_IN_CH4 = 0x46;
const int DLP_CMD_DIGITAL_IN_CH5 = 0x47;
const int DLP_CMD_DIGITAL_IN_CH6 = 0x4E;
const int DLP_CMD_DIGITAL_IN_CH7 = 0x4A;
const int DLP_CMD_DIGITAL_IN_CH8 = 0x4B;
const int DLP_CMD_ANALOG_IN_CH1 = 0x5A;
const int DLP_CMD_ANALOG_IN_CH2 = 0x58;
const int DLP_CMD_ANALOG_IN_CH3 = 0x43;
const int DLP_CMD_ANALOG_IN_CH4 = 0x56;
const int DLP_CMD_ANALOG_IN_CH5 = 0x42;
const int DLP_CMD_ANALOG_IN_CH6 = 0x4E;
const int DLP_CMD_ANALOG_IN_CH7 = 0x4D;
const int DLP_CMD_ANALOG_IN_CH8 = 0x2C;
const int DLP_CMD_TEMPERATURE_IN_CH1 = 0x39;
const int DLP_CMD_TEMPERATURE_IN_CH2 = 0x30;
const int DLP_CMD_TEMPERATURE_IN_CH3 = 0x2D;
const int DLP_CMD_TEMPERATURE_IN_CH4 = 0x3D;
const int DLP_CMD_TEMPERATURE_IN_CH5 = 0x4F;
const int DLP_CMD_TEMPERATURE_IN_CH6 = 0x50;
const int DLP_CMD_TEMPERATURE_IN_CH7 = 0x5B;
const int DLP_CMD_TEMPERATURE_IN_CH8 = 0x5D;
const int DLP_SETUP_FARENHEIT = 0x4C; // not used
const int DLP_SETUP_CELCIUS = 0x3B; // not used
const int DLP_SETUP_ASCII = 0x60;
const int DLP_SETUP_BINARY = 0x5C;
const int DLP_CMD_PING = 0x27;
const int DLP_RESP_PING = 0x51;
const int SET_MODE_ASCII = 0;
const int SET_MODE_BINARY = 1;
const float AD_MULTIPLIER = 5.0/1024.0;
void setup() {
Serial.begin(115200);
pinMode(A0,INPUT);
pinMode(A1,INPUT);
pinMode(A2,INPUT);
pinMode(A3,INPUT);
pinMode(A4,INPUT);
pinMode(A5,INPUT);
}
int rxByte = 0;
int currMode = SET_MODE_ASCII;
int sensorValue = 0;
void loop()
{
if (Serial.available() > 0)
{
rxByte = Serial.read();
int sendADVal = false;
int sendTempVal = false;
switch (rxByte)
{
case DLP_SETUP_ASCII:
currMode = SET_MODE_ASCII;
break;
case DLP_SETUP_BINARY:
currMode = SET_MODE_BINARY;
break;
case DLP_SETUP_FARENHEIT:
break; // not used
case DLP_SETUP_CELCIUS:
break; // not used
case DLP_CMD_PING:
// ping response
Serial.write(DLP_RESP_PING);
break;
case DLP_CMD_ANALOG_IN_CH1:
sensorValue = analogRead(A0);
sendADVal = true;
break;
case DLP_CMD_ANALOG_IN_CH2:
sensorValue = analogRead(A1);
sendADVal = true;
break;
case DLP_CMD_ANALOG_IN_CH3:
sensorValue = analogRead(A2);
sendADVal = true;
break;
case DLP_CMD_ANALOG_IN_CH4:
sensorValue = analogRead(A3);
sendADVal = true;
break;
case DLP_CMD_ANALOG_IN_CH5:
sensorValue = analogRead(A4);
sendADVal = true;
break;
case DLP_CMD_ANALOG_IN_CH6:
sensorValue = analogRead(A5);
sendADVal = true;
break;
case DLP_CMD_ANALOG_IN_CH7:
case DLP_CMD_ANALOG_IN_CH8:
sensorValue = 0; // not available
sendADVal = true;
break;
case DLP_CMD_TEMPERATURE_IN_CH1:
case DLP_CMD_TEMPERATURE_IN_CH2:
case DLP_CMD_TEMPERATURE_IN_CH3:
case DLP_CMD_TEMPERATURE_IN_CH4:
case DLP_CMD_TEMPERATURE_IN_CH5:
case DLP_CMD_TEMPERATURE_IN_CH6:
case DLP_CMD_TEMPERATURE_IN_CH7:
case DLP_CMD_TEMPERATURE_IN_CH8:
sensorValue = 0; // not available
sendTempVal = true;
break;
default:
break;
}
if (sendADVal || sendTempVal)
{
if (currMode == SET_MODE_BINARY)
{
Serial.write((char)(sensorValue >> 8));
Serial.write((char)(sensorValue));
}
else
{
Serial.print((float)sensorValue * AD_MULTIPLIER,2);
Serial.println("V");
}
}
}
}