daily pastebin goal
11%
SHARE
TWEET

Untitled

a guest Sep 14th, 2018 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const int Button = 2;
  2. const int Led1= 9;
  3. const int Led2 = 10;
  4. const int Led3 = 8;
  5. int count = 0;
  6. bool lastValue= false;
  7. bool currentValue=false;
  8. const int pinPot=A0;
  9. int readValue;
  10.  
  11. void setup()
  12. {
  13. pinMode(pinPot, INPUT);
  14. pinMode(Button, INPUT);
  15. pinMode(Led1, OUTPUT);
  16. pinMode(Led2, OUTPUT);
  17. pinMode(Led3, OUTPUT);
  18. Serial.begin(9600);
  19. }
  20. void loop()
  21. {
  22.   boolean current = digitalRead(Button);
  23.   if (lastValue != current)
  24.   {
  25.     delay(5);
  26.     currentValue = digitalRead(Button);
  27.     Serial.println(lastValue);
  28.   }     // will go and read the Button
  29. if (lastValue == LOW && currentValue == HIGH)    // Checks if the button has been pressed
  30.  {
  31.     count = random(1,7);
  32.     Serial.println(count);
  33.  }
  34.  switch(count)
  35.  {
  36.   case 1:
  37. analogWrite(Led1,readValue/4);
  38. analogWrite(Led2,LOW);
  39. analogWrite(Led3,LOW);
  40. analogWrite(Led4,LOW);
  41. analogWrite(Led5,LOW);
  42. analogWrite(Led6,LOW);
  43. analogWrite(Led7,LOW);
  44. break;
  45.  case 2:
  46.  analogWrite(Led1,readValue/4);
  47.  analogWrite(Led2,readValue/4);
  48.  analogWrite(Led3,LOW);
  49.  break;
  50.  case 3:
  51.   analogWrite(Led1,readValue/4);
  52.   analogWrite(Led2,readValue/4);
  53.   analogWrite(Led3,readValue/4);
  54.   break;
  55.    default:
  56.   analogWrite(Led1,LOW);
  57.   analogWrite(Led2,LOW);
  58.   analogWrite(Led3,LOW);
  59.   analogWrite(Led4,LOW);
  60. analogWrite(Led5,LOW);
  61. analogWrite(Led6,LOW);
  62. analogWrite(Led7,LOW);
  63.  
  64.   break;
  65. }
  66.  
  67. lastValue = currentValue;
  68. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top