MUstar

IoT 아두이노 0421 - LED_RGB(gogo2)

Apr 21st, 2017
77
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // LED control value
  2. #define OFF 0
  3. #define RED 0x01
  4. #define GREEN 0x02
  5. #define BLUE 0x04
  6.  
  7. int pin_GND = 11;
  8. int pin_LED[3] = {8, 9, 10};
  9. int a,i;
  10.  
  11. void setup() {
  12. pinMode(pin_GND, OUTPUT); //GOUND
  13. pinMode(pin_LED[0], OUTPUT); //R_LED
  14. pinMode(pin_LED[1], OUTPUT); //G_LED
  15. pinMode(pin_LED[2], OUTPUT); //B_LED
  16. digitalWrite(pin_GND, LOW);
  17. }
  18. void loop (){
  19. for(i=0;i<4;i++){if(i>=3)i=4;LED_control(i);delay(2000);LED_control(0);delay(100);}
  20. LED_control(0);delay(2000);
  21. }
  22. void LED_control(uint8_t da)
  23. {
  24. digitalWrite(pin_LED[0], da & 0x01);
  25. da >>=1;
  26. digitalWrite(pin_LED[1], da & 0x01);
  27. da >>=1;
  28. digitalWrite(pin_LED[2], da & 0x01);
  29. }
RAW Paste Data