Alex_isaac

Arduino DIY easy LED controller

May 15th, 2016
478
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //these are your Arduino outputs
  2. int led1 = 4; //Red
  3. int led2 = 5; //Green
  4. int led3 = 6; //Blue
  5. int var = 0; //random var
  6.  
  7. void setup() {
  8. pinMode(led1,OUTPUT); //don't forget too tell the IDE they are OUTPUTs
  9. pinMode(led2,OUTPUT);
  10. pinMode(led3,OUTPUT);
  11. }
  12.  
  13. void loop() {
  14.  
  15. var = random(7); //use 7 because you have 7 possibilities (0->6 makes 7)
  16.  
  17. if (var == 0){
  18.   red();
  19. }
  20. if (var == 1){
  21.   green();
  22. }
  23. if (var == 2){
  24.   blue();
  25. }
  26. if (var == 3){
  27.   rg();
  28. }
  29. if (var==4){
  30.   gb();
  31. }
  32. if (var == 5){
  33.   rb();
  34. }
  35. if (var == 6){
  36.   white();
  37. }
  38.  
  39. delay(2000); //change this value too change the delay between each color change (it's in ms, 2000 = 2s)
  40.  
  41. }
  42.  
  43. float red(){
  44.   digitalWrite(led1,HIGH);
  45.   digitalWrite(led2,LOW);
  46.   digitalWrite(led3,LOW);
  47.   }
  48. float green(){
  49.   digitalWrite(led1,LOW);
  50.   digitalWrite(led2,HIGH);
  51.   digitalWrite(led3,LOW);
  52.   }
  53. float blue(){
  54.   digitalWrite(led1,LOW);
  55.   digitalWrite(led2,LOW);
  56.   digitalWrite(led3,HIGH);
  57.   }
  58. float rg(){
  59.   digitalWrite(led1,HIGH);
  60.   digitalWrite(led2,HIGH);
  61.   digitalWrite(led3,LOW);
  62.   }
  63. float gb(){
  64.   digitalWrite(led1,LOW);
  65.   digitalWrite(led2,HIGH);
  66.   digitalWrite(led3,HIGH);
  67.   }  
  68. float rb(){
  69.   digitalWrite(led1,HIGH);
  70.   digitalWrite(led2,LOW);
  71.   digitalWrite(led3,HIGH);
  72.   }
  73. float white(){
  74.   digitalWrite(led1,HIGH);
  75.   digitalWrite(led2,HIGH);
  76.   digitalWrite(led3,HIGH);
  77.   }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×