Paso 4: Escribir sus códigos de
Esta parte requiere cierta reflexión. Para hacer la X, Y y Z brillo control del eje del LED, que se deben conectar a los pines analógicos de Arduino.
Los códigos pueden ser similares a esto-
const int RedPin = 3;
const int GreenPin = 5;
const int BluePin = 6;
const int sensorPinRed = A0;
const int sensorPinGreen = A2;
const int sensorPinBlue = A4;
int var = 1;
int minReadingRed = 750;
int maxReadingRed = 0;
int minReadingGreen = 750;
int maxReadingGreen = 0;
int minReadingBlue = 750;
int maxReadingBlue = 0;
int analogValue = 0;
int tiempo;
int analogOut;
flash int;
void setup() {}
Serial.Begin(9600);
Serial.println();
}
void loop() {}
al mismo tiempo (tiempo < 1000) {}
tiempo = millis();
analogWrite (RedPin, 255);
analogWrite (GreenPin, 255);
analogWrite (BluePin, 255);
retrasar (1000);
analogWrite (RedPin, 0);
analogWrite (GreenPin, 0);
analogWrite (BluePin, 0);
Delay (10);
}
mientras que (tiempo > 1000 & & tiempo < 16000) {}
tiempo = millis();
analogValue = analogRead(sensorPinRed);
maxReadingRed = max (analogValue, maxReadingRed);
minReadingRed = min (analogValue, minReadingRed);
Serial.Print ("Red analógica");
Serial.Print (analogValue, DEC);
Delay (20);
analogValue = analogRead(sensorPinGreen);
maxReadingGreen = max (analogValue, maxReadingGreen);
minReadingGreen = min (analogValue, minReadingGreen);
Serial.Print ("verde analógica");
Serial.Print (analogValue, DEC);
Delay (20);
analogValue = analogRead(sensorPinBlue);
maxReadingBlue = max (analogValue, maxReadingBlue);
minReadingBlue = min (analogValue, minReadingBlue);
Serial.Print ("analógico azul");
Serial.println (analogValue, DEC);
Delay (20);
}
mientras que (tiempo > 16000 & & tiempo < 17000) {}
tiempo = millis();
analogWrite (RedPin, 255);
analogWrite (GreenPin, 255);
analogWrite (BluePin, 255);
retrasar (1000);
analogWrite (RedPin, 0);
analogWrite (GreenPin, 0);
analogWrite (BluePin, 0);
}
mientras que (var == 1) {}
minReadingRed = minReadingRed + 0.5 * (maxReadingRed - minReadingRed);
minReadingGreen = minReadingGreen + 0.5 * (maxReadingGreen - minReadingGreen);
minReadingBlue = minReadingBlue + 0.5 * (maxReadingBlue - minReadingBlue);
Serial.println();
Serial.Print ("minReadingRed =");
Serial.Print (minReadingRed, DEC);
Serial.Print ("maxReadingRed =");
Serial.println (maxReadingRed, DEC);
Serial.Print ("minReadingGreen =");
Serial.Print (minReadingGreen, DEC);
Serial.Print ("maxReadingGreen =");
Serial.println (maxReadingGreen, DEC);
Serial.Print ("minReadingBlue =");
Serial.Print (minReadingBlue, DEC);
Serial.Print ("maxReadingBlue =");
Serial.println (maxReadingBlue, DEC);
var = 2;
}
analogValue = analogRead(sensorPinRed);
analogValue = restringir (analogValue, minReadingRed, maxReadingRed);
Serial.Print ("analogValue rojo =");
Serial.Print(analogValue);
analogOut = mapa (analogValue, minReadingRed, maxReadingRed, 0, 255);
analogOut = restringir (analogOut, 0, 255);
Serial.Print ("escala");
Serial.Print (analogOut, DEC);
analogWrite (RedPin, analogOut);
analogValue = analogRead(sensorPinGreen);
analogValue = restringir (analogValue, minReadingGreen, maxReadingGreen);
Serial.Print ("verde =");
Serial.Print(analogValue);
analogOut = mapa (analogValue, minReadingGreen, maxReadingGreen, 0, 255);
analogOut = restringir (analogOut, 0, 255); Serial.Print ("escala");
Serial.Print (analogOut, DEC);
analogWrite (GreenPin, analogOut);
analogValue = analogRead(sensorPinBlue);
analogValue = restringir (analogValue, minReadingBlue, maxReadingBlue);
Serial.Print ("azul =");
Serial.Print(analogValue);
analogOut = mapa (analogValue, minReadingBlue, maxReadingBlue, 0, 255);
analogOut = restringir (analogOut, 0, 255);
Serial.Print ("escala");
Serial.println (analogOut, DEC);
analogWrite (BluePin, analogOut);
retraso (25);
analogValue = analogRead(sensorPinRed);
analogOut = mapa (analogValue, minReadingRed, maxReadingRed, 0, 255);
Serial.Print ("rojo =");
Serial.Print (analogValue, DEC);
analogWrite (RedPin, analogOut);
analogValue = analogRead(sensorPinGreen); analogOut = mapa (analogValue, minReadingGreen, maxReadingGreen, 0, 255);
Serial.Print ("verde =");
Serial.Print (analogValue, DEC);
analogWrite (GreenPin, analogOut);
analogValue = analogRead(sensorPinBlue);
analogOut = mapa (analogValue, minReadingBlue, maxReadingBlue, 0, 255);
Serial.Print ("azul =");
Serial.println (analogValue, DEC);
analogWrite (BluePin, analogOut);
Delay(25);