ASM and c , ATMEL STUDIO 7

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


Hello friends, I started a new project regarding the ws2812b led strips, my intention is to turn on a led and by means of a button move it through the strip with a random color, I have the function of sending the data of the strip working well, but When sending the data regarding the number of the LED that I want to turn on, in each call by means of the button to run a LED, the send function drags the previous data and when I modify the number of LEDs to turn on, I turn on all the above and the new one, I publish some of my code in case anyone is interested in supporting,

 

void cylonWithHueControl();

void showLED(unsigned char , unsigned char, unsigned char , unsigned char);

rgb_color HsvToRgb(unsigned char,unsigned char,unsigned char);



volatile unsigned char LEDPosicion = 0  ;

#define LED_COUNT 64   // cantidad de leds

rgb_color colors[LED_COUNT];  // ARREGLO DE ESTRUCTURAS DE TIPO CHAR



int main(void)

{

    

     DDRC &= (0<<PORTC0)  ; // PONEMOS EL PUERTO PORTC  COMO ENTRADA CON PULL-UP ACTIVA 

     PORTC |= (1<<PORTC0) ;   

     

     DDRC &=(0<<PORTC1) ;    //PORTC.0 COMO SALIDA DOS  

     PORTC |=(1<<PORTC1) ; 

     

    //LED_PORT &= ~(1<< LED_PIN) ;  // NO ES NECESARIO INICIALIZAR LOS PUERTOS AQUI , YA QUE EN LA FUNCION DE ENVIO SE 

    //ED_DDR |=(1<<LED_PIN);    // SE INCIALIZA LOS PUERTOS , SI  LO HACEMOS AQUI TENEMOS COMFLICTO AL MOMENTO DE PRENDER EL LED INDICADO 

                               // ENVIANDO PULSOS NO DESEADOS AL INICIO DEL PROGRAMA COSIDERAR ESO ...........

    

     while (1) {

    

    if (!(PINC & 0x01)){

         _delay_ms(80) ;

         if (!(PINC & 0x01)){

             LEDPosicion ++;

         }

    }

    else if(!(PINC & 0x02)){

          _delay_ms(80) ;

          if (!(PINC & 0x10)){

              LEDPosicion --;

          }

        

    }

    



        cylonWithHueControl();

        // fadeLEDs(10 , LEDPosicion , colors[LEDPosicion]);

        _delay_ms(100); 

        

        

  }

  

}

 

void cylonWithHueControl(){

     

    unsigned char POTVal =250; 

    unsigned char intensidad = 255; 

    

    showLED(LEDPosicion ,POTVal ,255,intensidad);  //LEDPosicion ,

    

    

    

}

 

void showLED(unsigned char  LEDPos , unsigned char H, unsigned char S, unsigned char V){  //unsigned int Posicion,

    

    

    colors[LEDPos] = HsvToRgb(H,S,V); 

    

    led_strip_write(colors,LED_COUNT); 

    

}

 

When I send the data with the address and color of the led to be turned on, it starts the one it started but I drag the previous ones, complicating my intention of just turning on the led, starting from the beginning of the strip and using the button to move it all over it, but when the program runs at the moment of scrolling, they all start from the beginning onwards.

 I think I am assigning the data of the new position of the led to turn on and also the data that are previously in the arrangement of structures are straining, turning on all at the same time. and not just one as I would like.

my doubt is like aria so that only the led I want to light up and being able to move it through the led strip -> by means of a button by means of a counter. ????

 

 

 

 

 

jhordy

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


I solved it using a reset function of the LED strip, sending a plot of pure zeros, but I don't know if it is the most optimal for my code,



void clearTiraled (rgb_color * colors) {

  for (unsigned char i = 0; i <= LED_COUNT; i ++) {

  colors [i] = (rgb_color) {0,0,0};

    }

}

 

 

 

I am not an expert when it comes to programming, I am waiting for some opinion to improve and optimize my code, referring to sending data to the LED strip in order to modify it according to the data I am sending you.

 

jhordy

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Seems like you understand your problem and you have a solution - you need to turn off the previous led before the new one. In showLed have a variable that remembers the last led position, clears the lst led then sets the new led. Last led position = new led position.

Also note that you do not limit the value of LEDPocition - it can only be 0..63

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hi. If I have seen that showLed function, if I am not mistaken it is written entirely in c ++ and is not currently compatible with atmel studio 7, regarding the above, is what I do with the void function clearTiraled (rgb_color * colors) () ??? Or is there something more optimal that I would do? Do you have any advice for me? , How else could I improve my code regarding my problem. I would like to have a second opinion.

jhordy