Advertisement
NicoVape

Untitled

Feb 21st, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.82 KB | None | 0 0
  1.  
  2. const byte inputPotentiometer = 1;
  3. const byte inputSwitch = 8;
  4. const byte outputPWM = 5;
  5. const byte outputLed = 9;
  6. int fire;
  7. int pwm;
  8.  
  9. int getPWMValue() {
  10.   return map( analogRead( inputPotentiometer ), 0, 1023, 0, 255 );
  11. }
  12.  
  13. void setup()
  14. {
  15.  // Declaration des pin utilisée par la board
  16.   pinMode( inputPotentiometer, INPUT );
  17.   pinMode( inputSwitch, INPUT_PULLUP );
  18.   pinMode( outputPWM, OUTPUT );
  19.   pinMode( outputLed, OUTPUT );
  20.   fire = 0;
  21.   pwm = 0;
  22.  
  23. }
  24.  
  25. void loop()
  26. {
  27.   pwm = getPWMValue();
  28.   fire = digitalRead( inputSwitch );
  29.   if ( fire  == 1 ){
  30.     digitalWrite( outputLed, LOW );
  31.     analogWrite( outputPWM, 0 );  
  32.   }
  33. if (fire == 0){
  34.   digitalWrite( outputLed, HIGH );
  35.   analogWrite( outputPWM, pwm );
  36. } else {
  37.   digitalWrite( outputLed, LOW );
  38.   analogWrite( outputPWM, 0 );  
  39. };
  40. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement