about atmel teading over usb

Discussion in 'Programmer's Corner' started by Kardo22, Apr 23, 2014.

  1. Kardo22

    Thread Starter New Member

    Mar 12, 2014
    26
    0
    I don't get the example from Atmel:
    (http://www.atmel.com/Images/AVR328.zip)

    isn't led_state and led_number the same?
    I'm missing sth but what?
    Code ( (Unknown Language)):
    1. //* Read report from HID Generic Demo
    2.       U8 led_state;
    3.       U8 led_number;
    4.       led_state      = Usb_read_byte()&0x0F; // RepportOUT[0] is LEDS value
    5.       led_number     = Usb_read_byte()&0x0F;
    6.       switch (led_number)
    7.       {
    8.          case 1:
    9.             if(led_state)
    10.             {  Led0_on();   }
    11.             else {Led0_off();}
    12.             break;
    13.          case 2:
    14.             if(led_state)
    15.             {  Led1_on();   }
    16.             else {Led1_off();}
    17.             break;
    18.          case 3:
    19.             if(led_state)
    20.             {  Led2_on();   }
    21.             else {Led2_off();}
    22.             break;
    23.          case 4:
    24.             if(led_state)
    25.             {  Led3_on();   }
    26.             else {Led3_off();}
    27.             break;
    28.       }  
     
  2. ericgibbs

    AAC Fanatic!

    Jan 29, 2010
    2,503
    380
    led_state == On or Off
    led_number == the selected led.

    E
     
  3. Kardo22

    Thread Starter New Member

    Mar 12, 2014
    26
    0
    I understood that

    What I don't get is why do they get different value if both are U8 and get the value by:
    =Usb_read_byte()&0x0F;
     
  4. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,394
    1,606
    Because each call of the function reads the next byte, and one byte can be different from another.
     
    Kardo22 likes this.
Loading...