Advertisement
Hirsw0w

Untitled

May 17th, 2017
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. byte seven_seg_digits[10][7] = { { 1,1,1,1,1,1,0 }, // = 0
  2. { 0,1,1,0,0,0,0 }, // = 1
  3. { 1,1,0,1,1,0,1 }, // = 2
  4. { 1,1,1,1,0,0,1 }, // = 3
  5. { 0,1,1,0,0,1,1 }, // = 4
  6. { 1,0,1,1,0,1,1 }, // = 5
  7. { 1,0,1,1,1,1,1 }, // = 6
  8. { 1,1,1,0,0,0,0 }, // = 7
  9. { 1,1,1,1,1,1,1 }, // = 8
  10. { 1,1,1,0,0,1,1 } // = 9
  11. };
  12.  
  13. void setup() {
  14. // put your setup code here, to run once:
  15. analogReference(INTERNAL);
  16. for(byte i=0;i <= 13;i++) pinMode(i,OUTPUT);
  17.  
  18. pinMode(A5,OUTPUT);
  19. pinMode(A4,OUTPUT);
  20. }
  21.  
  22. void loop() {
  23. int reading = analogRead(A0);
  24. reading = map(reading,0,1023,0,112);
  25.  
  26. if(reading < 25) digitalWrite(A5,HIGH);
  27. else if(reading > 30) digitalWrite(A4,HIGH);
  28. else {
  29. digitalWrite(A5,LOW);
  30. digitalWrite(A4,LOW);
  31. }
  32.  
  33. sevenSegWrite(reading % 10,0);
  34. sevenSegWrite(reading / 10,7);4
  35.  
  36. }
  37.  
  38. void sevenSegWrite(byte digit,byte sPin) {
  39. for (byte i = 0; i < 7; ++i) {
  40. digitalWrite(sPin+i, !seven_seg_digits[digit][i]);
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement