Advertisement
tasosman

Untitled

Jun 25th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. #include "SevenSeg.h"
  2.  
  3.  
  4.  
  5. // Variables will change:
  6. int buttonPushCounter = 0; // counter for the number of button presses
  7. int buttonState = 0; // current state of the button
  8. int lastButtonState = 0; // previous state of the button
  9. int maxcounter = 99;
  10. int counter = 0;
  11. const int buttonPin = 2; // switch
  12.  
  13.  
  14. SevenSeg disp (10,9,8,7,6,11,12); //Defines the segments A-G: SevenSeg(A, B, C, D, E, F, G);
  15. const int numOfDigits =2; //number of 7 segments
  16. int digitPins [numOfDigits]={4,5}; //CC(or CA) pins of segment
  17.  
  18.  
  19. void setup() {
  20. Serial.begin(115200);
  21. disp.setDigitPins ( numOfDigits , digitPins );
  22. disp.setDutyCycle(60);
  23. pinMode(buttonPin, INPUT);
  24.  
  25.  
  26. }
  27.  
  28.  
  29. void loop() {
  30.  
  31. buttonState = digitalRead(buttonPin);
  32. if (buttonState != lastButtonState) {
  33. if (buttonState == HIGH) {
  34. Serial.println("on");
  35.  
  36.  
  37. while(counter < 100){
  38. counter++;
  39. if (digitalRead(buttonPin) != lastButtonState) {
  40. Serial.println(counter + String("/") + maxcounter );
  41. disp.write(counter);
  42. delay(1000);
  43. }else{
  44. delay(2000);//Anamonh 3 deuterolepta me to pou klisw to switch!
  45. Serial.println(String("0/99"));
  46. disp.write("00");
  47. counter = 0;
  48. break;
  49. }
  50.  
  51.  
  52. }
  53.  
  54. } else {
  55. Serial.println("off");
  56. }
  57. delay(1000);
  58. }
  59. lastButtonState = buttonState;
  60.  
  61.  
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement