Just wondering if I am missing something here or has this bloke made a stuff up in the code.
They use hardware pull down resistors on the input buttons and then code in input pullups to the same buttons.
//Winding Machine Arduino code by: Engineer USMAN AHMAD
//Easy HomeMade Projects (YouTube)
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);
int a = 0; // number of turns that are set initially
int c = 0; // current turns counter
int clr = 4;
int up = 5;
int down = 6;
int motor = 7;
int startt = 3;
int sn = 2;
int f = 0;
void setup() {
pinMode(motor,OUTPUT);
pinMode(clr,INPUT_PULLUP);
pinMode(startt, INPUT_PULLUP);
pinMode (up, INPUT_PULLUP);
pinMode (down, INPUT_PULLUP);
pinMode(sn, INPUT);
lcd.begin(); // begins connection to the LCD module
lcd.backlight(); // turns on the backlight
lcd.setCursor(0, 0);
lcd.print("SET TURNS = ");
lcd.setCursor(12, 0);
lcd.print(a);
lcd.setCursor(0, 1);
lcd.print("CRT TURNS = ");
lcd.setCursor(12, 1);
lcd.print(c);
digitalWrite(motor,LOW);
}
void loop()
{
if (digitalRead (up) == HIGH)
{
delay(200);
a=a+1;
if (a>3000)
{
a=3000;
}
while (digitalRead (up) == HIGH)
{
lcd.setCursor(12, 0); // set cursor to secon row
lcd.print(a);
lcd.print(" ");
delay(50);
a=a+10;
if (a>3000)
{
a=3000;
}
}
}
if (digitalRead (down) == HIGH)
{
delay(200);
a=a-1;
if (a<=0)
{
a=0;
}
while (digitalRead (down) == HIGH)
{
lcd.setCursor(12, 0); // set cursor to secon row
lcd.print(a);
lcd.print(" ");
delay(50);
a=a-10;
if (a<=0)
{
a=0;
}
}
}
lcd.setCursor(12, 0); // set cursor to secon row
lcd.print(a);
lcd.print(" ");
if(digitalRead(startt) == HIGH && c<a)
{
digitalWrite(motor,HIGH);
delay(250);
while(c != a)
{
if (digitalRead(sn) == HIGH && f == 0)
{
c = c + 1;
f = 1;
}
if (digitalRead(sn) == LOW && f == 1)
{
f = 0;
}
lcd.setCursor(12, 1);
lcd.print(c);
if (digitalRead(motor) == HIGH && digitalRead(startt) == HIGH )
{
digitalWrite(motor,LOW);
delay(200);
}
if (digitalRead(motor) == LOW && digitalRead(startt) == HIGH && c<a)
{
digitalWrite(motor,HIGH);
delay(200);
}
if (digitalRead(clr) == HIGH)
{
digitalWrite(motor,LOW);
delay(200);
break;
}
}
digitalWrite(motor,LOW);
delay(10);
}
if (digitalRead(clr) == HIGH)
{
c = 0;
lcd.setCursor(12, 1);
lcd.print(c);
lcd.print(" ");
delay(200);
while (digitalRead(clr) == HIGH)
{
delay(500);
if (digitalRead(clr) == HIGH)
{
a = 0;
lcd.setCursor(12, 0);
lcd.print(a);
lcd.print(" ");
}
}
}
}
