hmm I think I did not explain well ... no need to change the brightness, I need something like this:
for example:
if sensor is equal to 0V -> turns LED0
if sensor is equal to 0.1V -> turns LED1
if sensor is equal to 0.2V -> turns LED2
if sensor is equal to 0.3V -> turns LED3
if sensor is equal to 0.4V -> turns LED4
... ...
if sensor is equal to 0.3V -> turns LED3
if sensor is equal to 0.2V -> turns LED2
if sensor is equal to 0.1V -> turns LED1
if sensor is equal to 0V -> turns LED0
watch this video please:
My code is this now:
#include <lightuino3.h>
/* Asignación de pines del AVR a los MM5451 pines 4 a 7
(4 últimos del bloque)*/
int reloj = 5; // Reloj sincronización para los MM5451
int DatSerizq = 4; //Datos del MM5451 izq
int DatSerder = 6; //Datos del MM5451 der
int ctrlBrillo = 7; // Control de brillo CPU a MM5451's
/*****************************************************************
DECLARACIÓN DE VARIABLES GLOBALES
*****************************************************************/
int PinAnalogico = 0; //pin de entrada analógica
int val = 0; //var para guardar el valor leído por el conversor
float ledsr;
float ledcr;
int led;
/* Preparación del programa general */
void setup()
{
//Inicia el monitor serial arduino
Serial.begin(9600);
}//finaliza setup
int lectura()
{
val = analogRead(PinAnalogico);
/* analog in is of 0 to 1024 but my resolution es 0 to 70 LED
then 1024/69LED = 14.84 because my LED0 = 0V */
ledsr = val/14.84;
ledcr = ledsr +0.5;
led = (int) ledcr;
}
void loop() //*************************** FUNCION DE EJECUCION **************************************
{
/* Condiciones iniciales */
Lightuino board(reloj, DatSerizq, DatSerder, ctrlBrillo);
board.flags |= CCShield_FASTSET; //Respuesta rápida basada en registros
FlickerBrightness leds(board);
board.set(0x0UL, 0x0UL,0x0);//Apaga driver de LED's
leds.StartAutoLoop();//inicializa función autoloop para LED's
while (1)
{
lectura();
leds.brightness[led]= CCShield_MAX_BRIGHTNESS-1;
Serial.println(led);
delay(led);
lectura();
leds.brightness[led]= 0;
//leds.brightness[led]= CCShield_MAX_BRIGHTNESS-1;
}
}// Termina ejecución
thnks