Bonjour!
J'ai investi dans un ruban de 144 leds (acheté ici: http://www.amazon.fr/WS2812-Lumineuse-144LED-Etanche-Multicolore/dp/B00XJIS020/ref=sr_1_1?ie=UTF8&qid=1431528030&sr=8-1&keywords=144+Leds+WS2812B#productDetails); toujours des ws2812 qui sont commandables une par une aussi mais qui sont de la marque AUDEW. (sur le ruban de 12 la référence des LEDS est indiquées, sur celui de 144 LEDS non, je ne sais guère s'il y a une importance..)
Je souhaite récupérer des valeurs de plusieurs capteurs, et en fonction de ces valeurs; allumer en rougeou en vert les LEDS.
Seulement, les LEDS alternent entre rouge et vert, j'ai donc pensé à un problème de fréquence, mais même en modifiant la division de la fréquence d'horloge le problème persiste.
Pour le moment je n'utilise qu'un ruban de 72 LEDS qui récupère les valeurs de 2 capteurs.
Ensuite, je déclarerai 2 rubans de 72LEDS chacun pour gérer les 4 capteurs, mais je veux d'abord régler mon problème dh'olorge.
Mercu d'avance!
// Serial read of the linear sensor array TSL1412S (= the sensor with 1536 photodiodes)
//-------------------------------------------------------------------------------------
// NeoPixel Ring simple sketch (c) 2013 Shae Erisson
// released under the GPLv3 license to match the rest of the AdaFruit NeoPixel library
#include <Adafruit_NeoPixel.h>
#include <avr/power.h>
// Define various ADC prescaler:
const unsigned char PS_32 = (1 << ADPS2) | (1 << ADPS1) ; // division de la fréquence d'horloge par 32
const unsigned char PS_128 = (1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0);
int CLKpin = 48; // <-- Arduino pin delivering the clock pulses to pin 4 (CLK) of the TSL1412S
int SIpin = 6; // <-- Arduino pin delivering the SI (serial-input) pulse to pin 2 of the TSL1412S
int Apin1 = 1; // <-- Arduino pin connected to pin 12 (analog output 1)of the first TSL1412S
int Apin2 = 2; // <-- Arduino pin connected to pin 12 (analog output 1)of the second TSL1412S
int Apin3 = 3; // <-- Arduino pin connected to pin 12 (analog output 1)of the third TSL1412S
int Apin4 = 4; // <-- Arduino pin connected to pin 12 (analog output 1)of the fourth TSL1412S
float resultat1=0;
float resultat2=0;
float resultat3=0;
float resultat4=0;
int nled1=0;
int nled2=0;
int nled3=0;
int nled4=0;
// Which pin on the Arduino is connected to the NeoPixels?
// On a Trinket or Gemma we suggest changing this to 1
#define PIN 12
// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS 72
// When we setup the NeoPixel library, we tell it how many pixels, and which pin to use to send signals.
// Note that for older NeoPixel strips you might need to change the third parameter--see the strandtest
// example for more information on possible values.
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
int IntArray[1540]; // <-- the array where the readout of the photodiodes is stored, as integers
void setup()
{
pixels.begin(); // This initializes the NeoPixel library.
// Initialize two Arduino pins as digital output:
pinMode(CLKpin, OUTPUT);
pinMode(SIpin, OUTPUT);
pinMode(PIN,OUTPUT); //barrette's LED pin as output
// To set up the ADC, first remove bits set by Arduino library, then choose
// a prescaler: PS_16, PS_32, PS_64 or PS_128:
ADCSRA &= ~PS_128;
ADCSRA |= PS_32; // <-- Using PS_32 makes a single ADC conversion take ~30 us
// Next, assert default setting:
analogReference(DEFAULT);
// Set all IO pins low:
for( int i=0; i< 14; i++ )
{
digitalWrite(i, LOW);
}
// Clock out any existing SI pulse through the ccd register:
for(int i=0;i< 1540;i++)
{
ClockPulse();
}
// analogComparator.setOn(INTERNAL_REFERENCE, AIN1); // we instruct the lib to use volatges on the pins
// analogComparator.enableInterrupt(changeStatus, CHANGE); //we set the interrupt and when it has to be raised
Serial.begin(115200);
}
void loop() // repeat again and again
{
// Create a new SI pulse and clock out that same SI pulse through the sensor register:
digitalWrite(SIpin, HIGH);
ClockPulse();
digitalWrite(SIpin, LOW);
for(int i=0;i< 1540;i++)
{
ClockPulse();
}
// Stop the ongoing integration of light quanta from each photodiode by clocking in a SI pulse
// into the sensors register:
digitalWrite(SIpin, HIGH);
ClockPulse();
digitalWrite(SIpin, LOW);
for(int i=0; i < 1540; i++)
{
if((i%43)==0)
{
resultat1 = analogRead(Apin1);
nled1=i/43;
resultat2 = analogRead(Apin2);
nled2=i/43+36;
/* resultat3 = analogRead(Apin3);
nled3=i/86+36;
resultat4 = analogRead(Apin4);
nled4=i/86+54; */
if(resultat1>=500)
{
pixels.setPixelColor(nled1, pixels.Color(0,10,0));
pixels.show();
}
else
{
pixels.setPixelColor(nled1, pixels.Color(10,0,0));
pixels.show();
}
if(resultat2>=500)
{
pixels.setPixelColor(nled2, pixels.Color(0,10,0));
pixels.show();
}
else
{
pixels.setPixelColor(nled2, pixels.Color(10,0,0));
pixels.show();
}
/* if(resultat3>=500)
{
pixels.setPixelColor(nled3, pixels.Color(0,10,0));
pixels.show();
}
else
{
pixels.setPixelColor(nled3, pixels.Color(10,0,0));
pixels.show();
}
if(resultat4>=500)
{
pixels.setPixelColor(nled4, pixels.Color(0,10,0));
pixels.show();
}
else
{
pixels.setPixelColor(nled4, pixels.Color(10,0,0));
pixels.show();
}*/
}
ClockPulse();
}
}
// This function generates an outgoing clock pulse from the Arduino digital pin 'CLKpin'. This clock
// pulse is fed into pin 3 of the linear sensor:
void ClockPulse()
{
//delayMicroseconds(1);
digitalWrite(CLKpin, HIGH);
digitalWrite(CLKpin, LOW);
}