Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "SevenSeg.h"
- // Variables will change:
- int buttonPushCounter = 0; // counter for the number of button presses
- int buttonState = 0; // current state of the button
- int lastButtonState = 0; // previous state of the button
- int maxcounter = 99;
- int counter = 0;
- const int buttonPin = 2; // switch
- SevenSeg disp (10,9,8,7,6,11,12); //Defines the segments A-G: SevenSeg(A, B, C, D, E, F, G);
- const int numOfDigits =2; //number of 7 segments
- int digitPins [numOfDigits]={4,5}; //CC(or CA) pins of segment
- void setup() {
- Serial.begin(115200);
- disp.setDigitPins ( numOfDigits , digitPins );
- disp.setDutyCycle(60);
- pinMode(buttonPin, INPUT);
- }
- void loop() {
- buttonState = digitalRead(buttonPin);
- if (buttonState != lastButtonState) {
- if (buttonState == HIGH) {
- Serial.println("on");
- while(counter < 100){
- counter++;
- if (digitalRead(buttonPin) != lastButtonState) {
- Serial.println(counter + String("/") + maxcounter );
- disp.write(counter);
- delay(1000);
- }else{
- delay(2000);//Anamonh 3 deuterolepta me to pou klisw to switch!
- Serial.println(String("0/99"));
- disp.write("00");
- counter = 0;
- break;
- }
- }
- } else {
- Serial.println("off");
- }
- delay(1000);
- }
- lastButtonState = buttonState;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement