Hide minor edits - Show changes to markup
// Analog pin settings int aIn = 0; // Potentiometers connected to analog pins 0, 1, and 2 int bIn = 1; // (Connect power to 5V and ground to analog ground)
// Establecemos los pines analógicos int aIn = 0; // Potenciómetros conectados a los pines analógicos 0, 1 y 2 int bIn = 1; // (Conectar alimentación a 5V y masa a GND)
// Digital pin settings int aOut = 9; // LEDs connected to digital pins 9, 10 and 11 int bOut = 10; // (Connect cathodes to digital ground)
// Establecemos los pines digitales int aOut = 9; // LEDs conectados a los pines digitales 9, 10 y 11 int bOut = 10; // (Conectar los cátodos a GND)
// Values int aVal = 0; // Variables to store the input from the potentiometers
// Valores int aVal = 0; // Variables para almacenar las entradas de los potenciómetros
// Variables for comparing values between loops int i = 0; // Loop counter int wait = (1000); // Delay between most recent pot adjustment and output
int checkSum = 0; // Aggregate pot values
// Variables para comparar valores entre ciclos int i = 0; // contador de ciclo int wait = (1000); // retardo entre el mas reciente ajuste de potenciómetro y salida
int checkSum = 0; // sumar al valor del potenciómetro
int sens = 3; // Sensitivity theshold, to prevent small changes in
// pot values from triggering false reporting
// FLAGS int PRINT = 1; // Set to 1 to output values int DEBUG = 1; // Set to 1 to turn on debugging output
int sens = 3; // umbral de sensivilidad, para prevenir pequeños cambios en
// los valores de los potenciómetros debidos al ruido
// BANDERAS int PRINT = 1; // puesto a 1 para dar salida a los valores int DEBUG = 1; // puesto a 1 para conectar la salida de depurado
pinMode(aOut, OUTPUT); // sets the digital pins as output
pinMode(aOut, OUTPUT); // establece los pines digitales como salidas
Serial.begin(9600); // Open serial communication for reporting
Serial.begin(9600); // inicializa la comunicación serie
i += 1; // Count loop
aVal = analogRead(aIn) / 4; // read input pins, convert to 0-255 scale
i += 1; // contador de ciclos
aVal = analogRead(aIn) / 4; // lee los pines de entrada y escala 0-255
analogWrite(aOut, aVal); // Send new values to LEDs
analogWrite(aOut, aVal); // envía los nuevos valores a los LEDs
if (i % wait == 0) // If enough time has passed...
if (i % wait == 0) // si ha pasado suficiente tiempo...
checkSum = aVal+bVal+cVal; // ...add up the 3 values.
if ( abs(checkSum - prevCheckSum) > sens ) // If old and new values differ
// above sensitivity threshold
checkSum = aVal+bVal+cVal; // ...suma los tres valores.
if ( abs(checkSum - prevCheckSum) > sens ) // Si los viejos y los nuevos valores son diferentes
// por encima del umbral de sensivilidad
if (PRINT) // ...and if the PRINT flag is set...
if (PRINT) // ...y si la bandera PRINT está establecida...
Serial.print("A: "); // ...then print the values.
Serial.print("A: "); // ...imprime los valores.
PRINT = 1; // Re-set the flag
PRINT = 1; // resetea la bandera
prevCheckSum = checkSum; // Update the values
prevCheckSum = checkSum; // actualiza los valores
if (DEBUG) // If we want debugging output as well...
if (DEBUG) // si queremos salida de depurado...
if ( abs(checkSum - prevCheckSum) <= sens ) // If old and new values are
// within "sens" points...
if ( abs(checkSum - prevCheckSum) > sens ) // If old and new values differ
// above sensitivity threshold
// within sens points...
// within "sens" points...
[=
[=
=]
[=
/*
// Analog pin settings int aIn = 0; // Potentiometers connected to analog pins 0, 1, and 2 int bIn = 1; // (Connect power to 5V and ground to analog ground) int cIn = 2;
// Digital pin settings int aOut = 9; // LEDs connected to digital pins 9, 10 and 11 int bOut = 10; // (Connect cathodes to digital ground) int cOut = 11;
// Values int aVal = 0; // Variables to store the input from the potentiometers int bVal = 0; int cVal = 0;
// Variables for comparing values between loops int i = 0; // Loop counter int wait = (1000); // Delay between most recent pot adjustment and output
int checkSum = 0; // Aggregate pot values int prevCheckSum = 0; int sens = 3; // Sensitivity theshold, to prevent small changes in
// pot values from triggering false reporting
// FLAGS int PRINT = 1; // Set to 1 to output values int DEBUG = 1; // Set to 1 to turn on debugging output
void setup() {
pinMode(aOut, OUTPUT); // sets the digital pins as output pinMode(bOut, OUTPUT); pinMode(cOut, OUTPUT); Serial.begin(9600); // Open serial communication for reporting
}
void loop() {
i += 1; // Count loop
aVal = analogRead(aIn) / 4; // read input pins, convert to 0-255 scale bVal = analogRead(bIn) / 4; cVal = analogRead(cIn) / 4;
analogWrite(aOut, aVal); // Send new values to LEDs
analogWrite(bOut, bVal);
analogWrite(cOut, cVal);
if (i % wait == 0) // If enough time has passed...
{
checkSum = aVal+bVal+cVal; // ...add up the 3 values.
if ( abs(checkSum - prevCheckSum) <= sens ) // If old and new values are
// within sens points...
{
if (PRINT) // ...and if the PRINT flag is set...
{
Serial.print("A: "); // ...then print the values.
Serial.print(aVal);
Serial.print("\t");
Serial.print("B: ");
Serial.print(bVal);
Serial.print("\t");
Serial.print("C: ");
Serial.println(cVal);
PRINT = 0;
}
}
else
{
PRINT = 1; // Re-set the flag
}
prevCheckSum = checkSum; // Update the values
if (DEBUG) // If we want debugging output as well...
{
Serial.print(checkSum);
Serial.print("<=>");
Serial.print(prevCheckSum);
Serial.print("\tPrint: ");
Serial.println(PRINT);
}
}
}