#include <Wire.
h>
#include <LiquidCrystal_I2C.h>
// Initialize the LCD with I2C address 0x27, 16 columns, and 2 rows
LiquidCrystal_I2C lcd(0x27, 16, 2);
const char scrollText[] = " Insert 5 Peso for 2 Booklets ";
int RPWM = 5; // Digital/PWM pin 5 to the RPWM on the BTS7960
int LPWM = 6; // Digital/PWM pin 6 to the LPWM on the BTS7960
int stapler = 4;
int coin = 2;
// Enable "Left" and "Right" movement
int L_EN = 7; // connect Digital/PWM pin 7 to L_EN on the BTS7960
int R_EN = 8; // connect Digital/PWM pin 8 to R_EN on the BTS7960
volatile bool coinInserted = false;
void coinInterrupt()
{
coinInserted = true;
}
void setup() {
// put your setup code here, to run once:
pinMode(coin, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(coin), coinInterrupt, FALLING);
// initialize all our pins to output
for (int i = 5; i < 9; i++) {
pinMode(i, OUTPUT);
}
// set all the pins you want to use to LOW
for (int i = 5; i < 9; i++) {
digitalWrite(i, LOW);
}
delay(1000);// wait a second
[Link](9600);
pinMode (stapler, OUTPUT);
//enable "Right" and "Left" movement on the HBridge
// Notice use of digitalWrite to simply turn it on and keep it on.
digitalWrite(R_EN, HIGH);
digitalWrite(L_EN, HIGH);
[Link](); // Initialize the LCD
[Link](); // Turn on the backlight
}
void loop()
{
[Link](1, 0); // Set cursor to first row
[Link]("Reymundo Vendo"); // Static text on top row
// put your main code here, to run repeatedly:
int textLength = strlen(scrollText); // Get length of text
for (int i = 0; i < textLength - 15; i++)
{ // Scroll effect
[Link](0, 1); // Set cursor to second row
[Link](scrollText + i); // Print substring
delay(500); // Adjust speed of scrolling
}
if (coinInserted)
{
// Use an analogWrite(pin, which tells it to send a modulated
// signal (PWM) to specific pin at a specific "duty cycle".
// Valid values are 0 to 255. 0 means always off(or no power) and 255 means always on(full
power)
// [Link]
//booklet 1
[Link]();
[Link](2,0);
[Link]("Coin Inserted");
delay(500);
[Link](3,1);
[Link]("Dispensing 1");
//dispensing 1 starts
analogWrite(RPWM, 255); // pulse signal now at 128 (about half power... half of max 255).
delay(3000);
analogWrite(RPWM, 0);
delay(100);
analogWrite(LPWM, 255);
delay(50);
analogWrite(LPWM, 0);
delay(100);
analogWrite(RPWM, 255);
delay(100);
analogWrite(RPWM, 0);
//dispensing 1 ends
delay(1000);
//dispensing 2 starts
analogWrite(RPWM, 255); // pulse signal now at 128 (about half power... half of max 255).
delay(3000);
analogWrite(RPWM, 0);
delay(100);
analogWrite(LPWM, 255);
delay(50);
analogWrite(LPWM, 0);
delay(100);
analogWrite(RPWM, 255);
delay(100);
analogWrite(RPWM, 0);
delay(100);
//dispensing 2 ends
delay(1000);
[Link]();
delay(500);
[Link](3,0);
[Link]("Stapling");
//stapling starts
digitalWrite (stapler, HIGH);
delay(500);
digitalWrite (stapler, LOW);
delay (1000);
//stapling ends
delay(3000);
//booklet 2
[Link]();
[Link](2,0);
[Link]("Dispensing 2");
delay(500);
//dispensing 1 starts
analogWrite(RPWM, 255); // pulse signal now at 128 (about half power... half of max 255).
delay(3000);
analogWrite(RPWM, 0);
delay(100);
analogWrite(LPWM, 255);
delay(50);
analogWrite(LPWM, 0);
delay(100);
analogWrite(RPWM, 255);
delay(100);
analogWrite(RPWM, 0);
//dispensing 1 ends
delay(1000);
//dispensing 2 starts
analogWrite(RPWM, 255); // pulse signal now at 128 (about half power... half of max 255).
delay(3000);
analogWrite(RPWM, 0);
delay(100);
analogWrite(LPWM, 255);
delay(50);
analogWrite(LPWM, 0);
delay(100);
analogWrite(RPWM, 255);
delay(100);
analogWrite(RPWM, 0);
delay(100);
//dispensing 2 ends
delay(1000);
[Link]();
delay(500);
[Link](3,0);
[Link]("Stapling");
//stapling starts
digitalWrite (stapler, HIGH);
delay(500);
digitalWrite (stapler, LOW);
delay (1000);
[Link]();
[Link](3,0);
[Link]("Thank You");
delay(500);
[Link]();
delay(500);
coinInserted = false;
}
}