Advertisement
Guest User

Untitled

a guest
Sep 2nd, 2015
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. /* FILE: ARD_RGB_LED_MODULE_HCARDU0021_Example.pde
  2. DATE: 04/07/12
  3. VERSION: 0.1
  4.  
  5. This is a simple example of how to use the HobbyComponents RGB LED module
  6. (HCARDU0021). The module has 3 separate LED's (Red, Green & Blue) which
  7. Can be individually driven by applying a voltage to the appropriate module pin.
  8. This example uses the standard Arduino analogWrite (PWM) function to cycle
  9. through the full range of colours this module is capable of producing.
  10. Please be aware that this module does NOT include current limiting
  11. resistors and therefore you should not connect this module directly to the
  12. Arduino DIO pins.
  13.  
  14. SENSOR PINOUT:
  15.  
  16. PIN 1: GREEN LED +Ve
  17. PIN 2: RED LED +Ve
  18. PIN 3: BLUE LED +Ve
  19. PIN 4: GND
  20.  
  21. You may copy, alter and reuse this code in any way you like but please leave
  22. reference to HobbyComponents.com in your comments if you redistribute this code. */
  23.  
  24.  
  25. #define BLUE_LED_DIO 11 /* Select the DIO for driving the BLUE LED */
  26. #define RED_LED_DIO 9 /* Select the DIO for driving the RED LED */
  27. #define GREEN_LED_DIO 10 /* Select the DIO for driving the GREEN LED */
  28.  
  29. /* Initialise serial and DIO */
  30. void setup()
  31. {
  32. /* Configure the DIO pins used by the analogWrite PWM function */
  33. pinMode(BLUE_LED_DIO, OUTPUT);
  34. pinMode(RED_LED_DIO, OUTPUT);
  35. pinMode(GREEN_LED_DIO, OUTPUT);
  36. }
  37.  
  38. /* Main program loop */
  39. void loop()
  40. {
  41. int k;
  42.  
  43. /* Slowly reduce the red LED's intensity and at the same time
  44. increase the green LED's intensity */
  45. for (k = 0; k <=255; k++)
  46. {
  47. analogWrite(RED_LED_DIO,255 - k);
  48. analogWrite(GREEN_LED_DIO, k);
  49. delay(10);
  50. }
  51.  
  52. /* Slowly reduce the green LED's intensity and at the same time
  53. increase the blue LED's intensity */
  54. for (k = 0; k <=255; k++)
  55. {
  56. analogWrite(GREEN_LED_DIO,255 - k);
  57. analogWrite(BLUE_LED_DIO, k);
  58. delay(10);
  59. }
  60.  
  61. /* Slowly reduce the blue LED's intensity and at the same time
  62. increase the red LED's intensity */
  63. for (k = 0; k <=255; k++)
  64. {
  65. analogWrite(BLUE_LED_DIO,255 - k);
  66. analogWrite(RED_LED_DIO, k);
  67. delay(10);
  68. }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement