Guest User

Untitled

a guest
Dec 15th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. /*
  2. * Code d'exemple pour une LED RGB (+16 millions de couleurs).
  3. */
  4.  
  5. /* Broches */
  6. const byte PIN_LED_R = 9;
  7. const byte PIN_LED_G = 10;
  8. const byte PIN_LED_B = 11;
  9.  
  10.  
  11. /* Variables */
  12.  
  13. int i = 0;
  14. int r = 0;
  15. int g = 0;
  16. int b = 0;
  17.  
  18.  
  19. // Fonction setup(), appelée au démarrage de la carte Arduino
  20. void setup() {
  21.  
  22. // Initialise les broches
  23. pinMode(PIN_LED_R, OUTPUT);
  24. pinMode(PIN_LED_G, OUTPUT);
  25. pinMode(PIN_LED_B, OUTPUT);
  26. displayColor(0, 0, 0);
  27. }
  28.  
  29. // Fonction loop(), appelée continuellement en boucle tant que la carte Arduino est alimentée
  30. void loop() {
  31.  
  32. String temperature = "chaud";
  33. upLight(temperature);
  34. downLight(temperature);
  35.  
  36. }
  37.  
  38. void upLight(String temperature) {
  39. while(i<20) {
  40. displayColor(r,g,b);
  41. if (temperature == "chaud") {
  42. r++;
  43. g++;
  44. b = 0;
  45. } else if (temperature == "froid") {
  46. r = 0;
  47. g++;
  48. b++;
  49. }
  50. i++;
  51. delay(50);
  52. }
  53. downLight(temperature);
  54. }
  55.  
  56. void downLight(String temperature) {
  57. while(i>2) {
  58. displayColor(r,g,b);
  59. if (temperature == "chaud") {
  60. r--;
  61. g--;
  62. } else if (temperature == "froid") {
  63. g--;
  64. b--;
  65. }
  66. i--;
  67. delay(50);
  68. }
  69. upLight(temperature);
  70. }
  71.  
  72. /** Affiche une couleur */
  73. void displayColor(byte r, byte g, byte b) {
  74.  
  75. // Assigne l'état des broches
  76. // Version cathode commune
  77. analogWrite(PIN_LED_R, r);
  78. analogWrite(PIN_LED_G, g);
  79. analogWrite(PIN_LED_B, b);
  80. // Version anode commune
  81. //analogWrite(PIN_LED_R, ~r);
  82. //analogWrite(PIN_LED_G, ~g);
  83. //analogWrite(PIN_LED_B, ~b);
  84. }
Add Comment
Please, Sign In to add comment