Let me preface this with how much of an incredible novice at this i am. My profession is mechanical fitting and i would like to broaden my horizons! Coding is defiantly not a skill that comes naturally to me.
Let me firstly outline the aims of my project. The operator inputs on a keypad (https://tinyurl.com/y6twzxbr) either 1 or 2 displayed on a LCD(https://tinyurl.com/y9zt4x7o). The operator input triggers a program that runs a peristaltic pump(https://tinyurl.com/ybkm3ptd) on a given delay to deliver a known amount of liquid. I am using a Mega 2560 R3 with a linksprite motor shield v1.0b with the above components.
Now for my shameful attempt at coding.
#include <Keypad.h>
#include <UTFT.h> // Arduino LCD library
#include <SPI.h>
//TFT
UTFT myGLCD (ITDB18SP, 51, 50, 49, 48, 47);
extern uint8_t SmallFont[];
//TFT
// motor shield global constants start
int pinI1=8;//define I1 interface
int pinI2=11;//define I2 interface
int speedpinA=9;//enable motor A
int pinI3=12;//define I3 interface
int pinI4=13;//define I4 interface
int speedpinB=10;//enable motor B
int spead =127;//define the spead of motor
int delayTime =0;// setting delay time to integer
// Motorshield stop
char userInput='0';
//keypad variable and initialization
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
//define the cymbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {
{'0','1','2','3'},
{'4','5','6','7'},
{'8','9','A','B'},
{'C','D','E','F'}
};
byte rowPins[ROWS] = {25, 24, 23, 22}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {29, 28, 27, 26}; //connect to the column pinouts of the keypad
//initialize an instance of class NewKeypad
Keypad cKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
//keypad STOP
void setup(){
//MS
pinMode(pinI1,OUTPUT);
pinMode(pinI2,OUTPUT);
pinMode(speedpinA,OUTPUT);
pinMode(pinI3,OUTPUT);
pinMode(pinI4,OUTPUT);
pinMode(speedpinB,OUTPUT);
//MS
purge();
myGLCD.InitLCD(LANDSCAPE);
myGLCD.setFont(SmallFont);
myGLCD.print("Please enter program to run (1 or 2)", CENTER, 1);
char userInput = cKeypad.getKey(); // getting input that decides program to run
delay(250);
myGLCD.print(userInput, CENTER,12);
Serial.begin(9600);
}
void motor(){
analogWrite(speedpinA,spead);//input a simulation value to set the speed
digitalWrite(pinI2,LOW);//turn DC Motor A move anticlockwise
digitalWrite(pinI1,HIGH);
delay(delayTime);
stop();
}
void purge(){
analogWrite(speedpinA,spead);//input a simulation value to set the speed
digitalWrite(pinI2,LOW);//turn DC Motor A move anticlockwise
digitalWrite(pinI1,HIGH);
delay(delayTime);
stop();
}
void stop()//
{
digitalWrite(speedpinA,LOW);// Unenable the pin, to stop the motor. this should be done to avoid damaging the motor.
digitalWrite(speedpinB,LOW);
}
void loop(){
if (userInput == '1') {
delayTime = 1000;
motor();
}
if (userInput == '2'){
delayTime = 2000;
motor();}
Serial.print(userInput);
}
If someone could just point me to skills i can learn to complete this i would be appreciative.
Regards,