0% found this document useful (0 votes)
15 views13 pages

Code Arduino

This document describes code for controlling a stepper motor and interfacing with a LCD screen and keypad. It includes code to initialize a LiquidCrystal LCD screen and 4x4 keypad. Variables are declared to store user input numbers, operators, and calculation results. The keypad is used to input numbers and operators, with input displayed on the LCD. Calculations are performed when the equals key is pressed. Additional code controls a stepper motor by setting the direction and speed based on keypad input. The motor is stepped the calculated number of steps.

Uploaded by

Chaimae Flissi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views13 pages

Code Arduino

This document describes code for controlling a stepper motor and interfacing with a LCD screen and keypad. It includes code to initialize a LiquidCrystal LCD screen and 4x4 keypad. Variables are declared to store user input numbers, operators, and calculation results. The keypad is used to input numbers and operators, with input displayed on the LCD. Calculations are performed when the equals key is pressed. Additional code controls a stepper motor by setting the direction and speed based on keypad input. The motor is stepped the calculated number of steps.

Uploaded by

Chaimae Flissi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

#include

<LiquidCrystal.h>
#include <Keypad.h>

int x;
#define BAUD (9600)

LiquidCrystal lcd(7, 8, 9, 10, 11 , 12);


const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
{'1','2','3','+'},
{'4','5','6','-'},
{'7','8','9','*'},
{'X','0','=','/'},
};
byte rowPins[ROWS] = {53,51,49,47}; //connect to row pinouts
byte colPins[COLS] = {45,43,41,39}; //connect to column pinouts
Keypad myKeypad = Keypad( makeKeymap(keys), rowPins, colPins,
ROWS, COLS );

//variables declaration
boolean valOnePresent = false;
boolean next = false;
boolean final = false;
boolean calcul_termine = false;
String num1, num2;
int ans = 200;
int direction = 0;
char op;

void setup(){
pinMode(6,OUTPUT); // Enable
pinMode(5,OUTPUT); // Step
pinMode(4,OUTPUT); // Dir
digitalWrite(6, HIGH); // Set Enable low
lcd.begin(16,2);
lcd.setCursor(0,0);
lcd.print("Debit Volumique");
delay(2000);
lcd.clear(); //clears the LCD screen and positions the cursor
in the upper-left corner.

Serial.begin(BAUD);

void loop(){
char key = myKeypad.getKey();

if ((calcul_termine == false) && key != NO_KEY && (key=='1'||


key=='2'||key=='3'||key=='4'||key=='5'||key=='6'||key=='7'||
key=='8'||key=='9'||key=='0')){
if (valOnePresent != true){
num1 = num1 + key;
int numLength = num1.length();
lcd.setCursor(15 - numLength, 0); //to adjust one
whitespace for operator
lcd.print(num1);
}
else {
num2 = num2 + key;
int numLength = num2.length();
lcd.setCursor(15 - numLength, 1);
lcd.print(num2);
final = true;
}
}
else if ((calcul_termine == false) && (valOnePresent == false)
&& (key != NO_KEY) && (key == '/' || key == '*' || key == '-' ||
key == '+')){
if (valOnePresent == false){
valOnePresent = true;
op = key;
lcd.setCursor(15,0); //operator on right corner
lcd.print(op);
}
}

if ((calcul_termine == false) && (final == true) && (key !=


NO_KEY) && (key == '=')) {
if (op == '+'){

ans = num1.toInt()*425 ;
//1ml = 468pas et Dvmoteur = 0,2ml/s
}
lcd.clear();
lcd.setCursor(15,0);
lcd.autoscroll();
lcd.print(ans);
lcd.noAutoscroll();
calcul_termine = true;
valOnePresent = false;
final = false;

if (calcul_termine) {
//lcd.print(Saisir la direction:
delay(2000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Direction");
key = NO_KEY;
while ( key == NO_KEY) {
key = myKeypad.getKey();
}
if (key == '+') {
direction = 1;

}
else if (key == '-') {
direction = 2;
}
}
if ((key != NO_KEY) && (key == 'X')){
lcd.clear();
valOnePresent = false;
final = false;
num1 = "";
num2 = "";
ans = 0;
op = ' ';
}

if (direction == 1){
lcd.clear();
lcd.print("Direction +ve");

digitalWrite(6,LOW); // Set Enable low


digitalWrite(4,HIGH); // Set Dir high
for(int x = 0; x < ans; x++) // Loop 200 times
{

digitalWrite(5,HIGH); // Output high


delay(1); // Wait
digitalWrite(5,LOW); // Output low
delay(1); // Wait
}
delay(1000); // pause one second
direction = 0;
calcul_termine = false;
lcd.clear();
num1 = "";
num2 = "";
ans = 0;
op = ' ';
digitalWrite(6,HIGH); // Set Enable low
}

else if (direction == 2){


lcd.clear();
lcd.print("Direction -ve");

digitalWrite(6,LOW); // Set Enable low


digitalWrite(4,LOW); // Set Dir hig
for(int x = 0; x < ans; x++) // Loop 200 times
{

digitalWrite(5,HIGH); // Output high


delay(1); // Wait
digitalWrite(5,LOW); // Output low
delay(1); // Wait
}
delay(1000); // pause one second
direction = 0;
calcul_termine = false;
lcd.clear();
num1 = "";
num2 = "";
ans = 0;
op = ' ';
//lcd.setCursor(0,0);
digitalWrite(6,HIGH); // Set Enable low

}
MOTEUR ESSAI
#defin
e
pinEna
ble 13
//
Activa
tion
du
driver
/pilot
e
#define pinStep 9 // Signal de PAS (avancement)
#define pinDir 8 // Direction

enum{PUSH,PULL}; //syringe movement direction

void setup(){
Serial.begin(9600);
Serial.println("Test DRV8825");

pinMode( pinEnable, OUTPUT );


pinMode( pinDir , OUTPUT );
pinMode( pinStep , OUTPUT );
}

void loop(){
int i = 0;

digitalWrite( pinDir , HIGH); // Direction


avant
digitalWrite( pinStep , LOW); // Initialisation
de la broche step

// Avance de 200 pas

if (key != NO_KEY && (key=='1'||key=='2'||


key=='3'||key=='4'||key=='5'||key=='6'||key=='7'||
key=='8'||key=='9'||key=='0'||key == '/' || key ==
'*' || key == '-' || key == '+' )){
if (valOnePresent != true){
numop = numop + key;
if (temp_press==(numop'+')){
Serial.println("clockwise");
myStepper.step(stepsPerRevolution);
for( i=0; i<numop; i++){
Serial.println( i );
digitalWrite( pinStep, HIGH );
delay( 10 );
digitalWrite( pinStep, LOW );
delay( 10 );}
}
if (temp_press==(numop'-')){
Serial.println("counterclockwise");
myStepper.step(-stepsPerRevolution);
for( i=0; i<200; i++){ // Changer de
direction
Serial.println( i );
digitalWrite( pinStep, HIGH );
delay( 1 );
digitalWrite( pinStep, LOW );
delay( 1 );}
}
}
}

STEPPER MOTORO CONTROL SPEED

#incl
ude
<Step
per.h
>
#include <LiquidCrystal.h>
#include <Keypad.h>

// DEBUT partie Klcd

LiquidCrystal lcd(7, 8, 9, 10, 11 , 12);


const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
{'1','2','3','+'},
{'4','5','6','-'},
{'7','8','9','*'},
{'X','0','=','/'},
};
byte rowPins[ROWS] = {53,51,49,47}; //connect to row
pinouts
byte colPins[COLS] = {45,43,41,39}; //connect to
column pinouts
Keypad myKeypad = Keypad( makeKeymap(keys), rowPins,
colPins, ROWS, COLS );

//variables declaration
boolean valOnePresent = false;
boolean next = false;
boolean final = false;
String num;
int ans;
char op;

// FIN partie KLCD

// DEBUT Moteur Definitions

#define pinEnable 13 // Activation du driver/pilote


#define pinStep 9 // Signal de PAS (avancement)
#define pinDir 8 // Direction

// FIN Moteur
const int stepsPerRevolution = 200; // change this
to fit the number of steps per revolution
// for your motor

// initialize the stepper library on pins 8 through


11:
Stepper myStepper(stepsPerRevolution, 5, 6);

int stepCount = 0; // number of steps the motor has


taken

void setup(){
lcd.begin(16,2);
lcd.setCursor(0,0);
lcd.print("Debit Volumique");
delay(6000);
lcd.clear(); //clears the LCD screen and positions
the cursor in the upper-left corner.

pinMode( pinEnable, OUTPUT );


pinMode( pinDir , OUTPUT );
pinMode( pinStep , OUTPUT );

} ////
void loop(){
char key = myKeypad.getKey();

if (key != NO_KEY && (key=='1'||key=='2'||


key=='3'||key=='4'||key=='5'||key=='6'||key=='7'||
key=='8'||key=='9'||key=='0'|| key == '-')){
if (valOnePresent != true){
num = num + key;
int numLength = num.length();
lcd.setCursor(15 - numLength, 0); //to adjust
one whitespace for operator
lcd.print(num);
}////

// DEBUT MOTEUR

int i = 0;

digitalWrite( pinDir , HIGH); // Direction avant


digitalWrite( pinStep , LOW); // Initialisation
de la broche step

//FIN MOTEUR
if (final == true && key != NO_KEY && key == '='){

int Reading = digitalRead(num.toInt());


// map it to a range from 0 to 100:
int motorSpeed = map(Reading, -10000, 10000, -100,
100);
// set the motor speed:
if (motorSpeed > -10000) {
myStepper.setSpeed(motorSpeed);
// step 1/100 of a revolution:
myStepper.step(stepsPerRevolution / 100);
}
}

else if (key != NO_KEY && key == 'X'){


lcd.clear();
valOnePresent = false;
final = false;
num = "";
ans = 0;
op = ' ';
}
}
}

Keypad
#incl
ude
<Keyp
ad.h>

const
byte ROWS
= 4;
const
byte COLS
= 4;
char
keys[ROWS
][COLS] =
{

{'1','2',
'3','A'},

{'4','5',
'6','B'},

{'7','8',
'9','C'},

{'*','0',
'#','D'},
};
byte
rowPins[R
OWS] =
{3,4,5,6}
;
//connect
to row
pinouts
byte
colPins[C
OLS] =
{7,8,9,10
};
//connect
to column
pinouts

Keypad
keypad =
Keypad( m
akeKeymap
(keys),
rowPins,
colPins,
ROWS,
COLS );

void
setup(){

Serial.be
gin(9600)
;
}

void
loop(){
char
key =
keypad.ge
tKey();

if (key
!=
NO_KEY){

Serial.pr
intln(key
);
}
}

You might also like