Advertisement
Guest User

Arduino

a guest
Jun 19th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. // Pins
  2. /****** PINS LEDS */
  3. const byte PIN_LED_R = 11;
  4. const byte PIN_LED_B = 10;
  5. const byte PIN_LED_G = 9;
  6.  
  7. /****** PINS SWITCH */
  8. const byte PIN_SWITCH = 4;
  9.  
  10. /****** PINS POTENTIOMETER */
  11. const byte PIN_POTENTIO_R = 'A0';
  12. const byte PIN_POTENTIO_B = 'A1';
  13. const byte PIN_POTENTIO_G = 'A2';
  14.  
  15. int PotentioR = 0;
  16. int PotentioB = 0;
  17. int PotentioG = 0;
  18.  
  19. void Led_color(byte r, byte b, byte g)
  20. {
  21. analogWrite(PIN_LED_R, r);
  22. analogWrite(PIN_LED_B, b);
  23. analogWrite(PIN_LED_G, g);
  24. }
  25.  
  26. void setup()
  27. {
  28. Led_color(0, 255, 0);
  29.  
  30. //Pins LEDS
  31. pinMode(PIN_LED_R, OUTPUT);
  32. pinMode(PIN_LED_G, OUTPUT);
  33. pinMode(PIN_LED_B, OUTPUT);
  34.  
  35. //Pins SWITCH
  36. pinMode(PIN_SWITCH, INPUT);
  37.  
  38. //Pins POTENTIO
  39. pinMode(PIN_POTENTIO_R, INPUT);
  40. pinMode(PIN_POTENTIO_B, INPUT);
  41. pinMode(PIN_POTENTIO_G, INPUT);
  42. }
  43.  
  44. void loop()
  45. {
  46. delay(500);
  47.  
  48. //Potentio
  49. PotentioR = analogRead(PIN_POTENTIO_R);
  50. int Potentio_R = map(PotentioR,0,1023,0,255);
  51. PotentioG = analogRead(PIN_POTENTIO_G);
  52. int Potentio_G = map(PotentioG,0,1023,0,255);
  53. PotentioB = analogRead(PIN_POTENTIO_B);
  54. int Potentio_B = map(PotentioB,0,1023,0,255);
  55.  
  56. //Etat du switch
  57. int VALEUR_SWITCH = digitalRead(PIN_SWITCH);
  58.  
  59. if(VALEUR_SWITCH == HIGH)
  60. {
  61. Led_color(PIN_POTENTIO_R, PIN_POTENTIO_B, PIN_POTENTIO_G);
  62. }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement