Advertisement
gabbyshimoni

writePotValue-to-7seg

Jan 29th, 2019
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.99 KB | None | 0 0
  1. /*
  2.    29.01.2019
  3.    Written by: Gabby Shimoni
  4.    Description:
  5.    This program write the modulo of the potentiometer value by 10 to 7 segment
  6. */
  7.  
  8. int num_array[10][7] = {  { 1, 1, 1, 1, 1, 1, 0 }, // 0
  9.   { 0, 1, 1, 0, 0, 0, 0 }, // 1
  10.   { 1, 1, 0, 1, 1, 0, 1 }, // 2
  11.   { 1, 1, 1, 1, 0, 0, 1 }, // 3
  12.   { 0, 1, 1, 0, 0, 1, 1 }, // 4
  13.   { 1, 0, 1, 1, 0, 1, 1 }, // 5
  14.   { 1, 0, 1, 1, 1, 1, 1 }, // 6
  15.   { 1, 1, 1, 0, 0, 0, 0 }, // 7
  16.   { 1, 1, 1, 1, 1, 1, 1 }, // 8
  17.   { 1, 1, 1, 0, 0, 1, 1 }
  18. };   // 9
  19.  
  20. //function header
  21. void Num_Write(int);
  22.  
  23. #define potPin A0;
  24. int potValue = 0;
  25. void setup()
  26. {
  27.   // set pin modes
  28.   for (int k = 2; k < 9; k++)  pinMode(k, OUTPUT);
  29. }
  30.  
  31. void loop()
  32. {
  33.   potValue = analogRead(potPin);
  34.   potValue = potValue % 10;
  35.   Num_Write(potValue);
  36.   delay(1000);
  37. }
  38.  
  39. // this functions writes values to the sev seg pins
  40. void Num_Write(int number)
  41. {
  42.   int pin = 2;
  43.   for (int j = 0; j < 7; j++) {
  44.     digitalWrite(pin, num_array[number][j]);
  45.     pin++;
  46.   }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement