Hai peners kali ini saya mau bagikan sebuah script arduino, mudah mudahan bermanfaat bagi kalian semua, untuk tutorial video pemasangannya ada di link berikut. Membuat Mesin Cetak Antrian Menggunakan Arduino UNO R3
Script Arduion Mesin Cetak Nomor Antrian by Reza Rizki Maulana
Tested on Adruino UNO R3 SMD ATMEGA 328p & Thermal Printer GOOJPRT QR203
#include <PString.h>
#include <Adafruit_Thermal.h>
#include <Wire.h>
#include <RTClib.h>
RTC_DS1307 RTC;
#include <SoftwareSerial.h>
#define TX_PIN 6
#define RX_PIN 7
SoftwareSerial mySerial(RX_PIN, TX_PIN);
Adafruit_Thermal printer(&mySerial);
int hitung = 0;
const int buttonPin = 11;
const int buttonPin2 = 12;
const int buttonPin3 = 13;
int buttonState = 0;
int lastButtonState = LOW;
long lastDebounceTime = 0;
long debounceDelay = 50;
void setup() {
Wire.begin();
RTC.begin();
if (! RTC.isrunning()) {
Serial.println("RTC is NOT running!");
RTC.adjust(DateTime(__DATE__, __TIME__));
}
pinMode(buttonPin, INPUT_PULLUP);
pinMode(buttonPin2, INPUT_PULLUP);
pinMode(buttonPin3, INPUT_PULLUP);
mySerial.begin(9600);
printer.begin();
}
void loop() {
buttonState = digitalRead(buttonPin);
if (!buttonState) {
printer.wake();
printer.setDefault();
hitung += 1;
char buffer[40];
PString str(buffer, sizeof(buffer));
if (hitung < 100)
{
str.print(0);
if (hitung < 10)
{
str.print(0);
}
}
else if (hitung < 10)
{
str.print(0);
}
str.print(hitung);
printer.boldOn();
printer.justify('C');
printer.setSize('M');
printer.println(F("Nomor Antrian :"));
printer.setSize('L');
printer.println(str);
printer.setSize('S');
DateTime now = RTC.now();
str.begin();
str.print("tgl.");
str.print(now.day(), DEC);
str.print('-');
str.print(now.month(), DEC);
str.print('-');
str.print(now.year(), DEC);
str.print(' ');
int z = 0;
z = now.hour(), DEC;
if (z < 10)str.print('0');
str.print(z);
str.print(':');
z = now.minute(), DEC;
if (z < 10)str.print('0');
str.print(now.minute(), DEC);
str.print(':');
z = now.second(), DEC;
if (z < 10)str.print('0');
str.print(now.second(), DEC);
printer.println(str);
printer.println("dibuat oleh Reza RM");
printer.feed(6);
printer.sleep();
printer.wake();
printer.setDefault();
}
if (!(digitalRead(buttonPin2))) {
printer.wake();
printer.setDefault();
hitung -= 1;
char buffer[40];
PString str(buffer, sizeof(buffer));
if (hitung < 100)
{
str.print(0);
if (hitung < 10)
{
str.print(0);
}
}
else if (hitung < 10)
{
str.print(0);
}
if (hitung < 0)hitung = 0;
str.print(hitung);
printer.boldOn();
printer.justify('C');
printer.setSize('M');
printer.println(F("Nomor Antrian :"));
printer.setSize('L');
printer.println(str);
printer.setSize('S');
DateTime now = RTC.now();
str.begin();
str.print("tgl.");
str.print(now.day(), DEC);
str.begin();
str.print("tgl.");
str.print(now.day(), DEC);
str.print('-');
str.print(now.month(), DEC);
str.print('-');
str.print(now.year(), DEC);
str.print(' ');
int z = 0;
z = now.hour(), DEC;
if (z < 10)str.print('0');
str.print(z);
str.print(':');
z = now.minute(), DEC;
if (z < 10)str.print('0');
str.print(now.minute(), DEC);
str.print(':');
z = now.second(), DEC;
if (z < 10)str.print('0');
str.print(now.second(), DEC);
printer.println(str);
printer.println("dibuat oleh Reza RM");
printer.feed(6);
printer.sleep();
//delay(3000);
printer.wake();
printer.setDefault();
}
if (!(digitalRead(buttonPin))) {
printer.wake();
printer.setDefault();
printer.justify('C');
printer.setSize('M');
printer.println(F("Printer Direset"));
hitung = 0;
printer.feed(6);
printer.sleep();
//delay(3000);
printer.wake();
printer.setDefault();
}
}
Download Script Arduino .ino
Password : penaku-pertama.blogspot.com
Tidak ada komentar:
Posting Komentar