SHARE
TWEET

Untitled

a guest Oct 21st, 2019 83 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int seg_a = 3; //
  2. int seg_b = 2; //
  3. int seg_c = 8; //
  4. int seg_d = 7; //
  5. int seg_e = 6; //
  6. int seg_f = 4; //
  7. int seg_g = 5; //
  8. int btn = 10;
  9. int value = 0;
  10. int buttonPulledUp = 0;
  11. int lastState = 0;
  12.  
  13. void setup() {
  14.   //Serial.begin(9600);
  15.   pinMode( seg_a, OUTPUT );
  16.   pinMode( seg_b, OUTPUT );
  17.   pinMode( seg_c, OUTPUT );
  18.   pinMode( seg_d, OUTPUT );
  19.   pinMode( seg_e, OUTPUT );
  20.   pinMode( seg_f, OUTPUT );
  21.   pinMode( seg_g, OUTPUT );
  22.   pinMode( btn, INPUT_PULLUP);
  23.   digitalWrite(seg_a, HIGH );
  24.   digitalWrite(seg_b, HIGH );
  25.   digitalWrite(seg_c, HIGH );
  26.   digitalWrite(seg_d, HIGH );
  27.   digitalWrite(seg_e, HIGH );
  28.   digitalWrite(seg_f, HIGH );
  29.   //digitalWrite(seg_g, HIGH );
  30. }
  31.  
  32. void shut() {
  33.   digitalWrite(seg_a, LOW );
  34.   digitalWrite(seg_b, LOW );
  35.   digitalWrite(seg_c, LOW );
  36.   digitalWrite(seg_d, LOW );
  37.   digitalWrite(seg_e, LOW );
  38.   digitalWrite(seg_f, LOW );
  39.   digitalWrite(seg_g, LOW );
  40. }
  41.  
  42. void outp(int value) {
  43.   switch (value) {
  44.     case 9:
  45.       shut();
  46.       digitalWrite(seg_a, HIGH ); //8
  47.  
  48.       break;
  49.     case 8:
  50.       shut();
  51.       digitalWrite(seg_b, HIGH ); //8
  52.  
  53.       break;
  54.     case 7:
  55.       shut();
  56.       digitalWrite(seg_c, HIGH ); //7
  57.  
  58.       break;
  59.     case 6:
  60.       shut();
  61.       digitalWrite(seg_d, HIGH ); //6
  62.  
  63.       break;
  64.     case 5:
  65.       shut();
  66.       digitalWrite(seg_e, HIGH ); //5
  67.  
  68.       break;
  69.     case 4:
  70.       shut();
  71.       digitalWrite(seg_f, HIGH ); //4
  72.  
  73.       break;
  74.  
  75.   }
  76. }
  77.  
  78. void loop() {
  79.   buttonPulledUp = digitalRead(btn);
  80.   if (buttonPulledUp != lastState) {
  81.     if (!buttonPulledUp) {
  82.       value += 1;
  83.       outp(value);
  84.       delay(500);
  85.       buttonPulledUp = !buttonPulledUp;
  86.     }
  87.   }
  88.   if (value == 9)
  89.     value = -1;
  90.  
  91.   lastState = buttonPulledUp;
  92. }
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