_05_rgbLed.ino 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /***********************************************************
  2. File name: 05_rgbLed.ino
  3. Description:Control the RGB LED emitting red, green, blue, yellow,
  4. white and purple light, then the RGB LED will be off,
  5. each state continues 1s, after repeating the above
  6. procedure.
  7. Website: www.adeept.com
  8. E-mail: support@adeept.com
  9. Author: Tom
  10. Date: 2015/05/02
  11. *************************************************************/
  12. int redPin = 11; // R petal on RGB LED module connected to digital pin 11
  13. int greenPin = 10; // G petal on RGB LED module connected to digital pin 9
  14. int bluePin = 9; // B petal on RGB LED module connected to digital pin 10
  15. void setup()
  16. {
  17. pinMode(redPin, OUTPUT); // sets the redPin to be an output
  18. pinMode(greenPin, OUTPUT); // sets the greenPin to be an output
  19. pinMode(bluePin, OUTPUT); // sets the bluePin to be an output
  20. }
  21. void loop() // run over and over again
  22. {
  23. // Basic colors:
  24. color(255, 0, 0); // turn the RGB LED red
  25. delay(1000); // delay for 1 second
  26. color(0,255, 0); // turn the RGB LED green
  27. delay(1000); // delay for 1 second
  28. color(0, 0, 255); // turn the RGB LED blue
  29. delay(1000); // delay for 1 second
  30. // Example blended colors:
  31. color(255,255,0); // turn the RGB LED yellow
  32. delay(1000); // delay for 1 second
  33. color(255,255,255); // turn the RGB LED white
  34. delay(1000); // delay for 1 second
  35. color(128,0,255); // turn the RGB LED purple
  36. delay(1000); // delay for 1 second
  37. color(0,0,0); // turn the RGB LED off
  38. delay(1000); // delay for 1 second
  39. }
  40. void color (unsigned char red, unsigned char green, unsigned char blue)// the color generating function
  41. {
  42. analogWrite(redPin, 255-red); // PWM signal output
  43. analogWrite(greenPin, 255-green); // PWM signal output
  44. analogWrite(bluePin, 255-blue); // PWM signal output
  45. }