#include <SPI.
h>
#include <Wire.h>
#include <Entropy.h>
#include <Ethernet.h>
#include <TelnetClient.h>
#include <LiquidCrystal_I2C.h>
#define randomSeed(s) srandom(s)
int i = 0;
int days = 0;
int mins = 0;
int hours = 0;
int newmins = 0;
int newhours = 0;
int buttonPress = 0;
const int ledpin = 5;
const int coinpin = 2;
const int buttonpin = 3;
const int disablepin = 4;
volatile float coins = 0;
unsigned long startMillis = 0;
unsigned long currentMillis = 0;
uint32_t seed_value;
char letters[37] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '1', '2',
'3', '4', '5', '6', '7', '8', '9', '0'};
char script[56] = {'/', 'i', 'p', ' ', 'h', 'o', 't', 's', 'p', 'o', 't', ' ', 'u',
's', 'e', 'r', ' ', 'a', 'd', 'd', ' ', 'n', 'a', 'm', 'e', '=', '0', '0', '0',
'0', ' ', 'l', 'i', 'm', 'i', 't', '-', 'u', 'p', 't', 'i', 'm', 'e', '=', '0',
'0', 'd', '0', '0', ':', '0', '0', ':', '0', '0'};
LiquidCrystal_I2C lcd(0x27, 20, 4);
EthernetClient client;
telnetClient tc(client);
byte clientMAC[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress clientIp (192, 168, 88, 2);
//put here your router's ip address
IPAddress mikrotikRouterIp (192, 168, 88, 1);
void setup() {
pinMode(buttonpin, INPUT);
pinMode(ledpin, OUTPUT);
pinMode(disablepin, OUTPUT);
[Link]();
[Link]();
[Link]();
[Link](0, 0);
[Link]("initializing....");
[Link](0, 2);
[Link](" by asantos1");
delay(3000);
digitalWrite(disablepin, HIGH);
[Link](9600);
while (!Serial) {
; // wait for serial port to connect
}
[Link]();
attachInterrupt(digitalPinToInterrupt(coinpin), coinInterrupt, RISING);
}
void coinInterrupt() {
coins = coins + 1;
startMillis = millis(); //initial start time
}
void loop() {
if (coins < 1) {
//[Link]("Please Insert Coin");
[Link](0, 0);
[Link](" ");
[Link](0, 1);
[Link](" Insert Coin ");
[Link](0, 2);
[Link](" ");
[Link](0, 3);
[Link](" ");
}
currentMillis = millis(); //get the current time
if ((coins > 0) && (currentMillis - startMillis >= 100)) {
if (coins < 5) {
mins = coins * 15;
}
if (coins >= 5 && coins < 10) {
mins = coins * 30;
}
if (coins >= 10 && coins < 15) {
mins = coins * 45;
}
if (coins >= 15) {
mins = coins * 60;
}
hours = mins / 60;
days = hours / 24;
newhours = hours - (days * 24);
newmins = mins - (hours * 60);
script[44] = '0' + ((days / 10) % 10); // tens digit
script[45] = '0' + (days % 10); // ones digit
script[47] = '0' + ((newhours / 10) % 10); // tens digit
script[48] = '0' + (newhours % 10); // ones digit
script[50] = '0' + ((newmins / 10) % 10); // tens digit
script[51] = '0' + (newmins % 10); // ones digit
//[Link](coins);
//[Link](days);
//[Link](hours);
//[Link](newmins);
[Link](0, 0);
[Link](" Credit: ");
[Link](coins, 0);
[Link](".00 ");
[Link](0, 1);
[Link](" ");
[Link](hours);
[Link](" hrs ");
[Link](newmins);
[Link](" min ");
}
currentMillis = millis(); //get the current time
if ((coins > 0) && (currentMillis - startMillis >= 10000)) {
[Link](0, 2);
[Link](" Press Button to");
[Link](0, 3);
[Link](" Generate Code");
currentMillis = millis(); //get the current time
if ((coins > 0) && (currentMillis - startMillis >= 12000)) {
digitalWrite(disablepin, LOW);
digitalWrite(ledpin, HIGH);
while (digitalRead(buttonpin) == LOW) {
//do nothing
digitalWrite(ledpin, LOW);
seed_value = [Link]();
//[Link](seed_value);
randomSeed(seed_value);
script[26] = letters[random(0, 36)];
script[27] = letters[random(0, 36)];
script[28] = letters[random(0, 36)];
script[29] = letters[random(0, 36)];
script[56] = '\r';
//[Link](&script[26]);
[Link](0, 0);
[Link](" CODE GENERATED ");
[Link](0, 1);
[Link](" ");
[Link](0, 2);
[Link](" ");
[Link](script[26]);
[Link](" ");
[Link](script[27]);
[Link](" ");
[Link](script[28]);
[Link](" ");
[Link](script[29]);
[Link](" ");
[Link](0, 3);
[Link](" ");
[Link] (clientMAC);
//want to use dhcp?
if (![Link] (clientMAC)) {
[Link]("\r\nDHCP error");
[Link]();
[Link](0, 0);
[Link]("DCHP error");
while (1);
[Link]('>');
//PUT HERE YOUR USERNAME/PASSWORD
if ([Link](mikrotikRouterIp, "admin", "")) {
//[Link](mikrotikRouterIp, "admin", "", 1234) if you want to specify a port
different than 23
delay(1000);
[Link](script);
delay(5000);
[Link]();
[Link](0, 0);
[Link](" ");
[Link](0, 1);
[Link](" ");
[Link](script[26]);
[Link](" ");
[Link](script[27]);
[Link](" ");
[Link](script[28]);
[Link](" ");
[Link](script[29]);
[Link](" ");
[Link](0, 2);
[Link](" ");
[Link](0, 3);
[Link](" THANK YOU ");
delay(5000);
coins = 0;
digitalWrite(disablepin, HIGH);
}
}
}