Hi,
I found this code from another forum. I tried posting for help but the forum is dead. It's about Coin Acceptor control of video feed. I want to use/add an LCD instead of a 7segment. Here's the LCD info. https://www.adafruit.com/products/398
I am not a programmer, I hope someone could help. Thanks in advance.
P.S. If you want the link of source/forum, please let me know.
int coinPin = 2; //can change to anything you need
int relayPin = 5; //can change to anything you need
long time; //will keep track of the time the video should be turned off at
long timeToAddPerCoin = 420000; //420000 ms = 7min
long countdownDisplaytimer; //will keep track of when we should display
boolean isPlaying;
void setup(){
pinMode(coinPin, INPUT);
digitalWrite(coinPin, HIGH); // turn on pullup resistor
pinMode(relayPin, OUTPUT);
digitalWrite(relayPin, LOW);
pinMode(13, OUTPUT); //for the LED
Serial.begin(9600);
time = millis(); //set to right now, as the video should start off
countdownDisplaytimer = millis(); //set to right now
isPlaying = false;
}
void loop(){
if(digitalRead(coinPin) == LOW){ //assuming it goes high on coin insert
delay(500); //just to debounce
if(isPlaying){ //is video playing already?
time += timeToAddPerCoin; //add 7 minutes (420000 ms) to the time we need to turn the video off at
Serial.print("playing for ");
Serial.print(time / 60000);
Serial.println(" minutes");
}else{
time = millis() + timeToAddPerCoin; //set time to 7 minutes from now.
Serial.println("playing for 7 minutes");
isPlaying = true;
}
}
long timeLeft = time - millis();
long timeLeftInSeconds = timeLeft / 1000;
long timeSinceLastDisplay = millis() - countdownDisplaytimer;
if(timeLeft > 0){ //is there time left, and should keep playing the video?
//Serial.println(timeLeft); //DEBUGGING ONLY!!!
digitalWrite(relayPin, HIGH); //turn on the relay
digitalWrite(13, HIGH); // turn the LED next to pin 13
isPlaying = true;
if(countdownDisplaytimer > 1000){ //has it been a second since last diaplay?
countdownDisplaytimer = millis(); //reset timer
Serial.print(timeLeftInSeconds);
Serial.println(" seconds left");
}
}else{
digitalWrite(relayPin, LOW); //time ran out, turn off the relay
digitalWrite(13, LOW); // turn off LED next to pin 13
isPlaying = false;
}
}
I found this code from another forum. I tried posting for help but the forum is dead. It's about Coin Acceptor control of video feed. I want to use/add an LCD instead of a 7segment. Here's the LCD info. https://www.adafruit.com/products/398
I am not a programmer, I hope someone could help. Thanks in advance.
P.S. If you want the link of source/forum, please let me know.
int coinPin = 2; //can change to anything you need
int relayPin = 5; //can change to anything you need
long time; //will keep track of the time the video should be turned off at
long timeToAddPerCoin = 420000; //420000 ms = 7min
long countdownDisplaytimer; //will keep track of when we should display
boolean isPlaying;
void setup(){
pinMode(coinPin, INPUT);
digitalWrite(coinPin, HIGH); // turn on pullup resistor
pinMode(relayPin, OUTPUT);
digitalWrite(relayPin, LOW);
pinMode(13, OUTPUT); //for the LED
Serial.begin(9600);
time = millis(); //set to right now, as the video should start off
countdownDisplaytimer = millis(); //set to right now
isPlaying = false;
}
void loop(){
if(digitalRead(coinPin) == LOW){ //assuming it goes high on coin insert
delay(500); //just to debounce
if(isPlaying){ //is video playing already?
time += timeToAddPerCoin; //add 7 minutes (420000 ms) to the time we need to turn the video off at
Serial.print("playing for ");
Serial.print(time / 60000);
Serial.println(" minutes");
}else{
time = millis() + timeToAddPerCoin; //set time to 7 minutes from now.
Serial.println("playing for 7 minutes");
isPlaying = true;
}
}
long timeLeft = time - millis();
long timeLeftInSeconds = timeLeft / 1000;
long timeSinceLastDisplay = millis() - countdownDisplaytimer;
if(timeLeft > 0){ //is there time left, and should keep playing the video?
//Serial.println(timeLeft); //DEBUGGING ONLY!!!
digitalWrite(relayPin, HIGH); //turn on the relay
digitalWrite(13, HIGH); // turn the LED next to pin 13
isPlaying = true;
if(countdownDisplaytimer > 1000){ //has it been a second since last diaplay?
countdownDisplaytimer = millis(); //reset timer
Serial.print(timeLeftInSeconds);
Serial.println(" seconds left");
}
}else{
digitalWrite(relayPin, LOW); //time ran out, turn off the relay
digitalWrite(13, LOW); // turn off LED next to pin 13
isPlaying = false;
}
}