Advertisement
Zeda

Arduino 7-Segment, optimized

Oct 24th, 2017
558
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. //{pin2,pin3,pin4,pin5,pin6,pin7,pin8,pin9}
  2. const char num[80] = {
  3. 0,1,1,1,1,1,1,0, //0
  4. 0,1,0,0,1,0,0,0, //1
  5. 1,0,1,1,1,1,0,0, //2
  6. 1,0,1,1,0,1,1,0, //3
  7. 1,1,0,1,0,0,1,0, //4
  8. 1,1,1,0,0,1,1,0, //5
  9. 1,1,1,0,1,1,1,0, //6
  10. 0,1,1,1,0,0,1,0, //7
  11. 1,1,1,1,1,1,1,0, //8
  12. 1,1,1,1,0,1,1,0}; //9
  13. void setup() {
  14. for(int i=2;i<10;i++){
  15. pinMode(i, OUTPUT);
  16. digitalWrite(i, LOW);
  17. }
  18. }
  19.  
  20. void dispnum7segment(int n) {
  21. for(int i=0;i<8;i++){
  22. if(num[n*8+i]==1){digitalWrite(i+2,HIGH);}
  23. else{digitalWrite(i+2,LOW);
  24. }
  25. }
  26.  
  27. void loop() {
  28. for(int k=0;k<10;k++){
  29. dispnum7segment(k);
  30. delay(1000);
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement