daily pastebin goal
82%
SHARE
TWEET

Light Dimmer Dice

a guest Sep 14th, 2018 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const int lightone = 3;
  2. const int lighttwo = 11;
  3. const int lightthree = 5;
  4. const int lightfour = 6;
  5. const int lightfive = 9;
  6. const int lightsix = 10;
  7. const int lightseven = 7;
  8. const int button = 12;
  9. int count;
  10. bool currentValue = false;
  11. bool lastValue = false;
  12. const int pinPot = A0;
  13. int readVal;
  14.  
  15. void setup() {
  16.   // put your setup code here, to run once:
  17.   Serial.begin(9600);
  18.   pinMode (pinPot, INPUT);
  19.   pinMode (button, INPUT);
  20.   pinMode (lightone, OUTPUT);
  21.   pinMode (lighttwo, OUTPUT);
  22.   pinMode (lightthree, OUTPUT);
  23.   pinMode (lightfour, OUTPUT);
  24.   pinMode (lightfive, OUTPUT);
  25.   pinMode (lightsix, OUTPUT);
  26.   pinMode (lightseven, OUTPUT);
  27. }
  28.  
  29. void loop() {
  30.   // put your main code here, to run repeatedly:
  31.   readVal = analogRead(pinPot);
  32.   Serial.println(readVal);
  33.   readVal = readVal/4;
  34.   boolean current = digitalRead(button);
  35.     if (lastValue != current)
  36.     {
  37.       delay(5);
  38.       currentValue = digitalRead(button);
  39.     }
  40.     if (lastValue == LOW && currentValue == HIGH) {
  41.       count = random(1,7);
  42.       Serial.println(count);
  43.     }
  44.     switch(count) {
  45.       case 1:
  46.       analogWrite(lightone, LOW);
  47.       analogWrite(lighttwo, LOW);
  48.       analogWrite(lightthree, LOW);
  49.       analogWrite(lightfour, LOW);
  50.       analogWrite(lightfive, LOW);
  51.       analogWrite(lightsix, LOW);
  52.       analogWrite(lightseven, readVal);
  53.       break;
  54.      
  55.       case 2:
  56.       analogWrite(lightone, readVal);
  57.       analogWrite(lighttwo, LOW);
  58.       analogWrite(lightthree, LOW);
  59.       analogWrite(lightfour, LOW);
  60.       analogWrite(lightfive, LOW);
  61.       analogWrite(lightsix, readVal);
  62.       analogWrite(lightseven, LOW);
  63.       break;
  64.      
  65.       case 3:
  66.       analogWrite(lightone, readVal);
  67.       analogWrite(lighttwo, LOW);
  68.       analogWrite(lightthree, LOW);
  69.       analogWrite(lightfour, LOW);
  70.       analogWrite(lightfive, LOW);
  71.       analogWrite(lightsix, readVal);
  72.       analogWrite(lightseven, readVal);
  73.       break;
  74.      
  75.       case 4:
  76.       analogWrite(lightone, readVal);
  77.       analogWrite(lighttwo, LOW);
  78.       analogWrite(lightthree, readVal);
  79.       analogWrite(lightfour, readVal);
  80.       analogWrite(lightfive, LOW);
  81.       analogWrite(lightsix, readVal);
  82.       analogWrite(lightseven, LOW);
  83.       break;
  84.      
  85.       case 5:
  86.       analogWrite(lightone, readVal);
  87.       analogWrite(lighttwo, LOW);
  88.       analogWrite(lightthree, readVal);
  89.       analogWrite(lightfour, readVal);
  90.       analogWrite(lightfive, LOW);
  91.       analogWrite(lightsix, readVal);
  92.       analogWrite(lightseven, readVal);
  93.       break;
  94.      
  95.       case 6:
  96.       analogWrite(lightone, readVal);
  97.       analogWrite(lighttwo, readVal);
  98.       analogWrite(lightthree, readVal);
  99.       analogWrite(lightfour, readVal);
  100.       analogWrite(lightfive, readVal);
  101.       analogWrite(lightsix, readVal);
  102.       analogWrite(lightseven, LOW);
  103.       break;
  104.  
  105.       default:
  106.       analogWrite(lightone, LOW);
  107.       analogWrite(lighttwo, LOW);
  108.       analogWrite(lightthree, LOW);
  109.       analogWrite(lightfour, LOW);
  110.       analogWrite(lightfive, LOW);
  111.       analogWrite(lightsix, LOW);
  112.       analogWrite(lightseven, LOW);
  113.       break;
  114.     }
  115.     lastValue = currentValue;
  116.   }
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