🔒 Closed HELP! Arduino Piso net

Status
Not open for further replies.

ribbit

Eternal Poster
C++:
#include <TM1637Display.h>

#define CLK 7
#define DIO 6
#define coinSlotPin 8
const int RELAY_PIN = 9;
const int LED = A0;

boolean insertedCoin = false;
int totalCoin = 0;
int coinSlotStatus;
int chargeTime = 1;

TM1637Display display = TM1637Display(CLK, DIO);

unsigned long previousMillis = 0;
const long interval = 1000;

int hourUnit = 0;
int minUnit = 0;
int secUnit = 0;

int minOffSetValue = 0;
boolean countdown = false;

void setup() {
  Serial.begin(9600);
  pinMode(coinSlotPin, INPUT_PULLUP);
  pinMode(RELAY_PIN, OUTPUT);
  pinMode(LED, OUTPUT);
}

void loop() {
  while (!insertedCoin) {
    coinSlotStatus = digitalRead(coinSlotPin);
    timer();
    if (coinSlotStatus == 0) {
      countdown = true;
      insertedCoin = true;
      totalCoin += 1;
      minUnit = (totalCoin * chargeTime) + minOffSetValue - 1;
      secUnit = 59;
      if (hourUnit >= 59) {
        //hourUnit += 1;
       //minUnit = minUnit - 10;

        if (minUnit > 0) {
          minOffSetValue = minUnit;
          
        }
        totalCoin = 0;
      }
    }
  }

  while (insertedCoin) {
    coinSlotStatus = digitalRead(coinSlotPin);
    if (coinSlotStatus == 1) {
      insertedCoin = false;
    }
  }

}

void timer() {
  unsigned long currentMillis = millis();
  if (currentMillis - previousMillis >= interval) {
    previousMillis = previousMillis - currentMillis;
    printTime();
    countDown();
  }
}
void printTime() {
  if (countdown) {
    digitalWrite(RELAY_PIN, HIGH);
    digitalWrite(LED, LOW);
    display.setBrightness(1);
    display.showNumberDecEx(secUnit, 0, true, 2, 2);
    display.showNumberDecEx(minUnit, 0b11100000, true, 2, 0);

    if (hourUnit < 10) {
      Serial.print("0"); Serial.print(hourUnit);
    } else {
      Serial.print(hourUnit);
    }

    Serial.print(":");

    if (minUnit < 10) {
      Serial.print("0"); Serial.print(minUnit);
    } else {
      Serial.print(minUnit);
    }

    Serial.print(":");

    if (secUnit < 10) {
      Serial.print("0"); Serial.println(secUnit);
    } else {
      Serial.println(secUnit);
    }
  }
}

void countDown() {
  if (secUnit > 0) {
    secUnit -= 1;
    if (minUnit > 0) {
      if (secUnit < 1) {
        secUnit = 0;
        printTime();
        delay(interval);
        minUnit -= 1;
        secUnit = 59;
      }
    }

  } else {
    totalCoin = 0;
    countdown = false;
    digitalWrite(RELAY_PIN, LOW);
    digitalWrite(LED, HIGH);
    display.setBrightness(1);
    display.showNumberDec(0);
    Serial.println("Insert Coin to Start charging");
  }
}

eto po yung code
nakakapag add naman po nang oras kaso na rereset po yung time like nagiging 59 padin pag nag hulog nang piso ulit

baka meron po kayo reference alam na reference na pag nag add nang time na babawas sa current time di yung nag rereset
 
Status
Not open for further replies.

About this Thread

  • 2
    Replies
  • 1K
    Views
  • 2
    Participants
Last reply from:
ribbit

Online now

Members online
940
Guests online
1,572
Total visitors
2,512

Forum statistics

Threads
2,276,200
Posts
28,968,256
Members
1,231,160
Latest member
Thanatosbeljke
Back
Top