Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Adafruit_NeoPixel.h>
- // neopixel settings
- #define NOMBRE_LEDS 180
- #define LEDS_PIN 5
- #define NOMBRE_LED_COLONE 30
- #define NOMBRE_LED_COLONE_RED 30
- #define NOMBRE_LED_COLONE_ORANGE 30
- #define NOMBRE_LED_COLONE_YELLOW 30
- #define NOMBRE_LED_COLONE_GREEN 30
- #define NOMBRE_LED_COLONE_BLUE 30
- #define NOMBRE_LED_COLONE_PURPLE 30
- #define NOMBRE_COLONNE_STANDARD 6
- #define VITESSE_DEFILEMENT_MINI 25 //ms
- #define VITESSE_DEFILEMENT_MAXI 150 //ms
- #define SEUIL_INTENSITE_STANDARD 60
- #define SEUIL_INTENSITE_DEFILEMENT 140
- //Bouton
- #define BTN_CHANGEMENT_MODE 2 //digital 2
- #define BTN_MARCHE_ARRET 3 //digital 3
- #define TEMPS_ANTI_REBOND 250 //en ms
- #define TIME_LECTURE_ANALOGIQUE 250 //en ms
- //potentiometre
- #define INTENSITE_PIN A0
- #define VITESSE_PIN A1
- #define TRIGGER_VITESSE 5 // 5 % de variation du potentiometre vitesse pour prendre en compte
- // ------------------------- neopixel
- Adafruit_NeoPixel strip = Adafruit_NeoPixel(NOMBRE_LEDS, LEDS_PIN, NEO_GRB + NEO_KHZ800);
- int couleurSaturation = 50 ;
- struct colonneStandard{
- uint8_t nombreLed;
- int value_R;
- int value_G;
- int value_B;
- };
- colonneStandard colonneAffichageStandard[NOMBRE_COLONNE_STANDARD]={
- {NOMBRE_LED_COLONE_RED,couleurSaturation, 0, 0},
- {NOMBRE_LED_COLONE_ORANGE,couleurSaturation, (couleurSaturation / 2 ), 0},
- {NOMBRE_LED_COLONE_YELLOW,couleurSaturation, couleurSaturation , 0},
- {NOMBRE_LED_COLONE_GREEN,0, couleurSaturation, 0},
- {NOMBRE_LED_COLONE_BLUE,0, 0, couleurSaturation},
- {NOMBRE_LED_COLONE_PURPLE, (couleurSaturation / 2) ,0,( couleurSaturation / 2)}
- };
- //variables
- volatile unsigned long timeChangementMode=0;
- uint8_t modeAffichage = 0;
- uint8_t affichageStandardDemarrer = 0;
- volatile unsigned long timeMarcheArret=0;
- uint8_t marcheArret = 0;
- unsigned long timeVitesseDefilement=0;
- unsigned long timeLectureAnalogique=0;
- unsigned int vitesseDefilement = 50; //50ms
- int cpteurChenillard = 0;
- int lectureIntensite=0;
- int lectureIntensitePrecedent=0;
- int lectureVitesseDefilement=0;
- int lectureVitesseDefilementPrecedent=0;
- int tabLeds[NOMBRE_COLONNE_STANDARD];
- void initDepartColonne(){
- for(int i = 0 ; i < NOMBRE_COLONNE_STANDARD ; i++){
- if(!i) tabLeds[i]=0;
- else tabLeds[i]= tabLeds[i-1] + colonneAffichageStandard[i-1].nombreLed;
- }
- }
- void affichageStandard(){
- uint8_t leds = 0;
- if(couleurSaturation <= SEUIL_INTENSITE_STANDARD) couleurSaturation = SEUIL_INTENSITE_STANDARD;
- strip.setBrightness(couleurSaturation);
- for(uint8_t i = 0 ; i < NOMBRE_COLONNE_STANDARD ; i++){
- for(uint8_t j = 0 ; j < colonneAffichageStandard[i].nombreLed ; j++){
- strip.setPixelColor(leds, strip.Color(colonneAffichageStandard[i].value_R, colonneAffichageStandard[i].value_G, colonneAffichageStandard[i].value_B) );
- leds++;
- }
- }
- strip.show();
- }
- void eteintLed(){
- for (int i=0 ; i <=NOMBRE_LEDS ; i++){
- strip.setPixelColor(i, strip.Color(0,0,0));
- }
- strip.show();
- }
- int colonneBandeau(int numLed){
- int result=0;
- int nbrLed = 0 ;
- for(int i = 0 ; i < NOMBRE_COLONNE_STANDARD ; i++){
- nbrLed += colonneAffichageStandard[i].nombreLed;
- if(numLed < nbrLed ){
- result = i;
- break;
- }
- }
- return result;
- }
- int getCouleurColonne(int numColone,char couleur, uint8_t intensite){
- int result;
- if(couleur == 'R') result = colonneAffichageStandard[numColone].value_R * ((100.0 - (intensite * 10 ))/100.0);
- else if(couleur == 'G') result = colonneAffichageStandard[numColone].value_G * ((100.0 - (intensite * 10 ))/100.0);
- else if(couleur == 'B') result = colonneAffichageStandard[numColone].value_B * ((100.0 - (intensite * 10 ))/100.0);
- else result = 0;
- return result;
- }
- void chenillard(){
- if(couleurSaturation <= SEUIL_INTENSITE_DEFILEMENT ) couleurSaturation = SEUIL_INTENSITE_DEFILEMENT;
- strip.setBrightness(couleurSaturation);
- for(int i = 0 ; i < NOMBRE_LED_COLONE ; i++){
- for(int j = 0 ; j < NOMBRE_COLONNE_STANDARD ; j++){
- strip.setPixelColor(i+tabLeds[j], strip.Color(getCouleurColonne(j,'R',0),getCouleurColonne(j,'G',0),getCouleurColonne(j,'B',0)) );
- }
- if(cpteurChenillard > 9 && cpteurChenillard == i ){
- for(int k = 1 ; k<10 ; k++){
- for(int j = 0 ; j < NOMBRE_COLONNE_STANDARD; j++){
- strip.setPixelColor((i-k)+tabLeds[j], strip.Color(getCouleurColonne(j,'R',k),getCouleurColonne(j,'G',k),getCouleurColonne(j,'B',k)) );
- }
- }
- }
- if(cpteurChenillard > 8 && cpteurChenillard == i ){
- for(int k = 1 ; k<=9 ; k++){
- for(int j = 0 ; j < NOMBRE_COLONNE_STANDARD; j++){
- strip.setPixelColor((i-k)+tabLeds[j], strip.Color(getCouleurColonne(j,'R',k),getCouleurColonne(j,'G',k),getCouleurColonne(j,'B',k)) );
- }
- }
- }
- if(cpteurChenillard > 7 && cpteurChenillard == i ){
- for(int k = 1 ; k<=8 ; k++){
- for(int j = 0 ; j < NOMBRE_COLONNE_STANDARD; j++){
- strip.setPixelColor((i-k)+tabLeds[j], strip.Color(getCouleurColonne(j,'R',k),getCouleurColonne(j,'G',k),getCouleurColonne(j,'B',k)) );
- }
- }
- }
- if(cpteurChenillard > 6 && cpteurChenillard == i ){
- for(int k = 1 ; k<=7 ; k++){
- for(int j = 0 ; j < NOMBRE_COLONNE_STANDARD; j++){
- strip.setPixelColor((i-k)+tabLeds[j], strip.Color(getCouleurColonne(j,'R',k),getCouleurColonne(j,'G',k),getCouleurColonne(j,'B',k)) );
- }
- }
- }
- if(cpteurChenillard > 5 && cpteurChenillard == i ){
- for(int k = 1 ; k<=6 ; k++){
- for(int j = 0 ; j < NOMBRE_COLONNE_STANDARD; j++){
- strip.setPixelColor((i-k)+tabLeds[j], strip.Color(getCouleurColonne(j,'R',k),getCouleurColonne(j,'G',k),getCouleurColonne(j,'B',k)) );
- }
- }
- }
- if(cpteurChenillard > 4 && cpteurChenillard == i ){
- for(int k = 1 ; k<=5 ; k++){
- for(int j = 0 ; j < NOMBRE_COLONNE_STANDARD; j++){
- strip.setPixelColor((i-k)+tabLeds[j], strip.Color(getCouleurColonne(j,'R',k),getCouleurColonne(j,'G',k),getCouleurColonne(j,'B',k)) );
- }
- }
- }
- else if(cpteurChenillard > 3 && cpteurChenillard == i ){
- for(int k = 1 ; k<=4 ; k++){
- for(int j = 0 ; j < NOMBRE_COLONNE_STANDARD; j++){
- strip.setPixelColor((i-k)+tabLeds[j], strip.Color(getCouleurColonne(j,'R',k),getCouleurColonne(j,'G',k),getCouleurColonne(j,'B',k)) );
- }
- }
- }
- else if(cpteurChenillard > 2 && cpteurChenillard == i ){
- for(int k = 1 ; k<=3 ; k++){
- for(int j = 0 ; j < NOMBRE_COLONNE_STANDARD; j++){
- strip.setPixelColor((i-k)+tabLeds[j], strip.Color(getCouleurColonne(j,'R',k),getCouleurColonne(j,'G',k),getCouleurColonne(j,'B',k)) );
- }
- }
- }
- else if(cpteurChenillard > 1 && cpteurChenillard == i ){
- for(int k = 1 ; k<=2 ; k++){
- for(int j = 0 ; j < NOMBRE_COLONNE_STANDARD; j++){
- strip.setPixelColor((i-k)+tabLeds[j], strip.Color(getCouleurColonne(j,'R',k),getCouleurColonne(j,'G',k),getCouleurColonne(j,'B',k)) );
- }
- }
- }
- else if(cpteurChenillard > 0 && cpteurChenillard == i ){
- for(int j = 0 ; j < NOMBRE_COLONNE_STANDARD; j++){
- strip.setPixelColor(tabLeds[j], strip.Color(getCouleurColonne(j,'R',1),getCouleurColonne(j,'G',1),getCouleurColonne(j,'B',1)) );
- }
- }
- else if(cpteurChenillard == 0 && cpteurChenillard == i ){
- for(int j = 0 ; j < NOMBRE_COLONNE_STANDARD; j++){
- strip.setPixelColor(tabLeds[j], strip.Color(getCouleurColonne(j,'R',0),getCouleurColonne(j,'G',0),getCouleurColonne(j,'B',0)) );
- }
- }
- else{
- for(int j = 0 ; j < NOMBRE_COLONNE_STANDARD; j++){
- strip.setPixelColor((i)+tabLeds[j], strip.Color(getCouleurColonne(j,'R',9),getCouleurColonne(j,'G',9),getCouleurColonne(j,'B',9)) );
- }
- }
- }
- strip.show();
- }
- void toggleChangementMode(){
- if( abs((millis() - timeChangementMode)) >= TEMPS_ANTI_REBOND){
- timeChangementMode=millis();
- modeAffichage = !modeAffichage;
- }
- }
- void toggleMarcheArret(){
- if( abs((millis() - timeMarcheArret)) >= TEMPS_ANTI_REBOND){
- timeMarcheArret=millis();
- marcheArret = !marcheArret;
- }
- }
- void setup() {
- Serial.begin(115200);
- while (!Serial);
- Serial.println("demarrage...");
- Serial.flush();
- pinMode(LEDS_PIN, OUTPUT);
- pinMode(BTN_CHANGEMENT_MODE, INPUT_PULLUP); //quand appuyer la lecture du btn vaux 0 ou low sinon il est a 1 - HIGH
- pinMode(BTN_MARCHE_ARRET, INPUT_PULLUP); //quand appuyer la lecture du btn vaux 0 ou low sinon il est a 1 - HIGH
- digitalWrite(LEDS_PIN, LOW);
- digitalWrite(BTN_CHANGEMENT_MODE, HIGH);
- digitalWrite(BTN_MARCHE_ARRET, HIGH);
- attachInterrupt(digitalPinToInterrupt(BTN_CHANGEMENT_MODE),toggleChangementMode,FALLING);
- attachInterrupt(digitalPinToInterrupt(BTN_MARCHE_ARRET),toggleMarcheArret,FALLING);
- initDepartColonne();
- strip.begin();
- strip.show();
- eteintLed();
- }
- void loop() {
- if(!marcheArret){
- if(!modeAffichage){
- if( abs((millis() - timeLectureAnalogique)) >= TIME_LECTURE_ANALOGIQUE) {
- timeLectureAnalogique = millis();
- lectureIntensite = analogRead(INTENSITE_PIN);
- float borneSuperieur = lectureIntensite * (float) ((100.0 + TRIGGER_VITESSE)/100.0);
- float borneInferieur = lectureIntensite * (float) ((100.0 - TRIGGER_VITESSE)/100.0);
- if( (borneSuperieur <= lectureIntensitePrecedent) || (borneInferieur >= lectureIntensitePrecedent)){
- lectureIntensitePrecedent = lectureIntensite;
- couleurSaturation = map(lectureIntensite,0,1023,0,254);
- }
- affichageStandard();
- }
- if(!affichageStandardDemarrer) affichageStandard();
- }
- else {
- if( abs((millis() - timeLectureAnalogique)) >= TIME_LECTURE_ANALOGIQUE) {
- timeLectureAnalogique = millis();
- lectureIntensite = analogRead(INTENSITE_PIN);
- float borneSuperieur = lectureIntensite * (float) ((100.0 + TRIGGER_VITESSE)/100.0);
- float borneInferieur = lectureIntensite * (float) ((100.0 - TRIGGER_VITESSE)/100.0);
- if( (borneSuperieur <= lectureIntensitePrecedent) || (borneInferieur >= lectureIntensitePrecedent)){
- lectureIntensitePrecedent = lectureIntensite;
- couleurSaturation = map(lectureIntensite,0,1023,0,254);
- }
- lectureVitesseDefilement = analogRead(VITESSE_PIN);
- float vitesseBorneSuperieur = lectureVitesseDefilement * (float) ((100.0 + TRIGGER_VITESSE)/100.0);
- float vitesseBorneInferieur = lectureVitesseDefilement * (float) ((100.0 - TRIGGER_VITESSE)/100.0);
- if( (vitesseBorneSuperieur <= lectureVitesseDefilementPrecedent) || (vitesseBorneInferieur >= lectureVitesseDefilementPrecedent)){
- lectureVitesseDefilementPrecedent = lectureVitesseDefilement;
- vitesseDefilement = map(lectureVitesseDefilement,0,1023,VITESSE_DEFILEMENT_MINI,VITESSE_DEFILEMENT_MAXI);
- }
- }
- if(abs((millis() - timeVitesseDefilement)) >= vitesseDefilement){
- timeVitesseDefilement = millis();
- chenillard();
- (cpteurChenillard >= NOMBRE_LED_COLONE) ? cpteurChenillard = 0 : cpteurChenillard++;
- }
- }
- }
- else {
- eteintLed();
- affichageStandardDemarrer=0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement