Advertisement
raiffm21

Water Supply I

Jan 19th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. const int ser = 8;
  2. const int latch = 9;
  3. const int clk = 10;
  4. int Mandy [10] = {63, 5, 91, 79, 101, 110, 126, 7, 127, 103};
  5. const int water = A0;
  6. int waterSupply = 0;
  7. int digit = 0;
  8.  
  9. void setup()
  10. {
  11. pinMode (ser, OUTPUT);
  12. pinMode (latch, OUTPUT);
  13. pinMode (clk, OUTPUT);
  14. pinMode (water, INPUT);
  15. Serial.begin (9600);
  16. }
  17. l
  18. void loop()
  19. {
  20. waterSupply = analogRead (water);
  21. digit = map (waterSupply, 0, 300, 0, 9);
  22. digit = constrain (digit, 0, 9);
  23. Serial.println (waterSupply);
  24. switch (digit)
  25. {
  26. case 0:
  27. digitalWrite (latch, LOW);
  28. shiftOut (ser, clk, MSBFIRST, Mandy [0]);
  29. digitalWrite (latch, HIGH);
  30. break;
  31. case 1:
  32. digitalWrite (latch, LOW);
  33. shiftOut (ser, clk, MSBFIRST, Mandy [1]);
  34. digitalWrite (latch, HIGH);
  35. break;
  36. case 2:
  37. digitalWrite (latch, LOW);
  38. shiftOut (ser, clk, MSBFIRST, Mandy [2]);
  39. digitalWrite (latch, HIGH);
  40. break;
  41. case 3:
  42. digitalWrite (latch, LOW);
  43. shiftOut (ser, clk, MSBFIRST, Mandy [3]);
  44. digitalWrite (latch, HIGH);
  45. break;
  46. case 4:
  47. digitalWrite (latch, LOW);
  48. shiftOut (ser, clk, MSBFIRST, Mandy [4]);
  49. digitalWrite (latch, HIGH);
  50. break;
  51. case 5:
  52. digitalWrite (latch, LOW);
  53. shiftOut (ser, clk, MSBFIRST, Mandy [5]);
  54. digitalWrite (latch, HIGH);
  55. break;
  56. case 6:
  57. digitalWrite (latch, LOW);
  58. shiftOut (ser, clk, MSBFIRST, Mandy [6]);
  59. digitalWrite (latch, HIGH);
  60. break;
  61. case 7:
  62. digitalWrite (latch, LOW);
  63. shiftOut (ser, clk, MSBFIRST, Mandy [7]);
  64. digitalWrite (latch, HIGH);
  65. break;
  66. case 8:
  67. digitalWrite (latch, LOW);
  68. shiftOut (ser, clk, MSBFIRST, Mandy [8]);
  69. digitalWrite (latch, HIGH);
  70. break;
  71. case 9:
  72. digitalWrite (latch, LOW);
  73. shiftOut (ser, clk, MSBFIRST, Mandy [9]);
  74. digitalWrite (latch, HIGH);
  75. break;
  76. }
  77.  
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement