Imagine | Develop | Create

#include <LiquidCrystal.h>
#include <Servo.h>
#define upPIN 0
#define startstopPIN 18
#define downPIN 1
#define InPinA 17
#define InPinB 16
#define InSePinA 13
#define InSePinB 12
#define InSePinC 11
#define OutPinA 14
#define OutPinB 15
#define OutSePinA A5
#define OutSePinB A6
#define OutSePinC A7
Servo motorcontrol;
LiquidCrystal lcd(2, 3, 4,5, 6, 7);
unsigned long currenttime = 0;
double percent = 25;
bool active = false;
double val;
void setup()
{
lcd.begin(16, 2);
pinMode(startstopPIN, INPUT);
pinMode(downPIN, INPUT);
pinMode(upPIN, INPUT);
motorcontrol.attach(InPinA);
motorcontrol.write(10);
lcd.print(" Initialising ");
lcd.print(" motor ");
currenttime = millis();
while(currenttime+4000 >millis()){}
lcd.print("Motor: STOPPED ");
updateLCD();
}
void loop()
{
if(digitalRead(startstopPIN)==HIGH)
{
active = !active;
updateLCD();
while(digitalRead(startstopPIN)==HIGH){runMotor();}
}
if(digitalRead(upPIN)==HIGH)
{
percent++;
if(percent > 100)
{
percent =100;
}
updateLCD();
while(digitalRead(upPIN)==HIGH){runMotor();}
}
if(digitalRead(downPIN)==HIGH)
{
percent--;
if(percent < 0)
{
percent =0;
}
updateLCD();
while(digitalRead(downPIN)==HIGH){runMotor();}
}
runMotor();
}
void updateLCD()
{
lcd.setCursor(0,0);
if(active)
{
lcd.print("Motor: RUNNING");
}
else
{
lcd.print("Motor: STOPPED");
}
lcd.setCursor(0,1);
lcd.print("Power: ");
lcd.print(percent);
lcd.print("%");
}
void runMotor()
{
if(active == true)
{
double number = percent*0.01;
val = 80+55*number;
motorcontrol.write(val);
}
else
{
motorcontrol.write(0);
}
}