MUstar

IoT 아두이노 0421 - LED_RGB(5s)

Apr 21st, 2017
79
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 i;
  10.  
  11. void setup() {
  12. pinMode(pin_GND, OUTPUT); //GROUND
  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(500);LED_control(0);delay(500);}
  20. }
  21. void LED_control(uint8_t da)
  22. {
  23. digitalWrite(pin_LED[0], da & 0x01);
  24. da >>=1;
  25. digitalWrite(pin_LED[1], da & 0x01);
  26. da >>=1;
  27. digitalWrite(pin_LED[2], da & 0x01);
  28. }
RAW Paste Data