Outils pour utilisateurs

Outils du site


wiki:projets:titrimetre2:programmation

Ceci est une ancienne révision du document !


Partie programmation

#include <LiquidCrystal.h> LiquidCrystal lcd(42, 41, 35, 34, 33, 32); 6 pin #include <Keypad.h> const byte ROWS = 4; nb lignes const byte COLS = 3; nb colonnes char keys[ROWS][COLS] = { {'1','2','3'}, {'4','5','6'}, {'7','8','9'}, {'.','0','#'} }; byte rowPins[ROWS] = {46, 47, 48, 49}; 4 pin byte colPins[COLS] = {50, 51, 52}; 3 pin Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS ); const int agitateur = 26; 1 pin

capteur const int s0 = 18; const int s1 = 19; const int s2 = 22; const int s3 = 21; const int out = 20; /*int rouge = 0; int vert = 0; int bleu = 0; */ int couleur[3]; moteur int delaylegnth = 5; Change la vitesse du pousse seringue, plus delaylgnth est élévé, plus le pousse seringue est lent int fincourse = 1023; Variable du capteur de fin de course

const float vpas = 0.268;

void color(){

digitalWrite(s2, LOW);  
digitalWrite(s3, LOW);  
//count OUT, pRed, RED  
couleur[0] = pulseIn(out, digitalRead(out) == HIGH ? LOW : HIGH);  
digitalWrite(s3, HIGH);  
//count OUT, pBLUE, BLUE  
couleur[1] = pulseIn(out, digitalRead(out) == HIGH ? LOW : HIGH);  
digitalWrite(s2, HIGH);  
//count OUT, pGreen, GREEN  
couleur[2] = pulseIn(out, digitalRead(out) == HIGH ? LOW : HIGH);  
}

/* digitalRead(out) == HIGH ? LOW : HIGH est équivalent à if (led_state == HIGH) led_state = LOW else led_state = HIGH; */

int pousse_seringue(int nbpas) int → none Fait tourner le moteur du pousse seringue de nbpas pas. {

if (nbpas < 0)
{
  for (int i=0; i< (-nbpas / 4); i++)
  {
    digitalWrite(9, LOW);  //ENABLE CH A
digitalWrite(8, HIGH); //DISABLE CH B
digitalWrite(12, HIGH);   //Sets direction of CH A
analogWrite(3, 255);   //Moves CH A

delay(delaylegnth);

digitalWrite(9, HIGH);  //DISABLE CH A
digitalWrite(8, LOW); //ENABLE CH B
digitalWrite(13, LOW);   //Sets direction of CH B
analogWrite(11, 255);   //Moves CH B

delay(delaylegnth);

digitalWrite(9, LOW);  //ENABLE CH A
digitalWrite(8, HIGH); //DISABLE CH B
digitalWrite(12, LOW);   //Sets direction of CH A
analogWrite(3, 255);   //Moves CH A

delay(delaylegnth);
  
digitalWrite(9, HIGH);  //DISABLE CH A
digitalWrite(8, LOW); //ENABLE CH B
digitalWrite(13, HIGH);   //Sets direction of CH B
analogWrite(11, 255);   //Moves CH B

delay(delaylegnth);
  }    
}
if (nbpas > 0)
{
  for (int i=0; i< (nbpas / 4); i++)
  {
    digitalWrite(9, LOW);  //ENABLE CH A
digitalWrite(8, HIGH); //DISABLE CH B
digitalWrite(12, HIGH);   //Sets direction of CH A
analogWrite(3, 255);   //Moves CH A

delay(delaylegnth);

digitalWrite(9, HIGH);  //DISABLE CH A
digitalWrite(8, LOW); //ENABLE CH B
digitalWrite(13, HIGH);   //Sets direction of CH B
analogWrite(11, 255);   //Moves CH B

delay(delaylegnth);

digitalWrite(9, LOW);  //ENABLE CH A
digitalWrite(8, HIGH); //DISABLE CH B
digitalWrite(12, LOW);   //Sets direction of CH A
analogWrite(3, 255);   //Moves CH A

delay(delaylegnth);
  
digitalWrite(9, HIGH);  //DISABLE CH A
digitalWrite(8, LOW); //ENABLE CH B
digitalWrite(13, LOW);   //Sets direction of CH B
analogWrite(11, 255);   //Moves CH B

delay(delaylegnth);
  }
}

}

void initialisation_pousse_seringue() /*lance l'initialisation du pousse seringue : le pousse seringue recule en fin de course, on dispose de 10 sec pour mettre la seringue qui doit avoir un peu plus de 15 mL, puis le pousse seringue vide la seringue jusqu'a être sur la graduation des 15 mL Branchements du capteur de fin de course :

  1. fil rouge : 5V
  2. fil jaune : GND
  3. fil blanc : pin A15 */

{

lcd.clear();
lcd.print("initialisation");
while (fincourse != 0)
{
  pousse_seringue(-10);
  Serial.println(fincourse);
  fincourse = analogRead(A14);
  
}
//delay(10000);
lcd.clear();
lcd.print("pipette");
lcd.setCursor(0,1);
lcd.print("pret ?");
bool eta = false;
while (eta != true){
char touche = keypad.getKey();
if (touche == '#'){
eta = true;
}
}
lcd.clear();
lcd.print("initialisation");
pousse_seringue(2200);
lcd.clear();

}

void setup() {

pinMode(A15,INPUT);

pinMode(26,OUTPUT); digitalWrite(agitateur,HIGH); delay(100); digitalWrite(agitateur,LOW);

//establish motor direction toggle pins
pinMode(12, OUTPUT); //CH A -- HIGH = forwards and LOW = backwards???
pinMode(13, OUTPUT); //CH B -- HIGH = forwards and LOW = backwards???

//establish motor brake pins
pinMode(9, OUTPUT); //brake (disable) CH A
pinMode(8, OUTPUT); //brake (disable) CH B
Serial.begin(9600);

lcd.begin(16,2); nb colonnes, lignes lcd.print(“test”); delay(100); lcd.clear(); keypad.setDebounceTime(20); temps de réponse du clavier moteur.setSpeed(30); nb tour par min moteur

capteur pinMode(s0, OUTPUT); pinMode(s1, OUTPUT); pinMode(s2, OUTPUT); pinMode(s3, OUTPUT); pinMode(out, INPUT); digitalWrite(s0, HIGH); digitalWrite(s1, HIGH); Serial.begin(9600); } void loop(){ choix couleur /*bool eta = false; char couleur = 'a'; lcd.print(“1:R 2:V 3:B?”); lcd.setCursor(0, 1); while (eta != true){

char touche = keypad.getKey();
if (touche != NO_KEY){
    lcd.print(touche);
    couleur = touche;
}
if ((couleur = '1') || (couleur = '2') || (couleur = '3')){
  if (touche = '#'){
    eta = true;
  }
}

} eta=false; lcd.clear();*/

bool eta = false; String co = String(); String vo = String(); String vt = String(); String fc = String();

lcd.print(“Facteur”); lcd.setCursor(0, 1); while (eta != true){

char touche = keypad.getKey();
if (touche == '*'){
  fc = "";
  lcd.clear();
  lcd.print("facteur");
  lcd.setCursor(0, 1);
}
else if (touche != NO_KEY && touche != '#'){
  fc += touche;
  lcd.setCursor(0,1);
  lcd.print(fc);
}
if (touche == '#' && fc != ""){
  eta=true;
}

} lcd.clear(); eta=false;

lcd.print(“C MOL/L”); lcd.setCursor(0, 1); while (eta != true){

char touche = keypad.getKey();
if (touche == '*'){
  co = "";
  lcd.clear();
  lcd.print("C MOL/L");
  lcd.setCursor(0, 1);
}
else if (touche != NO_KEY && touche != '#'){
  co += touche;
  lcd.setCursor(0,1);
  lcd.print(co);
}
if (touche == '#' && co != ""){
  eta=true;
}

} lcd.clear(); eta=false;

lcd.print(“V mL”); lcd.setCursor(0, 1); while (eta != true){

char touche = keypad.getKey();
if (touche == '*'){
  vo = "";
  lcd.clear();
  lcd.print("V mL");
  lcd.setCursor(0, 1);
}
else if (touche != NO_KEY && touche != '#'){
  vo += touche;
  lcd.setCursor(0,1);
  lcd.print(vo);
}
if (touche == '#' && vo != ""){
  eta=true;
}

} lcd.clear(); eta=false;

/*lcd.print(“INIT MOT”); while (opto < 50)

{
  pousse_seringue(-12);
  opto = analogRead(A0);
}
while (opto > 50)
{
  opto = analogRead(A0);
}
pousse_seringue(1200);

while(eta==false){

char touche = keypad.getKey();
if (touche == '#'){
  eta = true;
}
pousse_seringue(-12);

} pousse_seringue(100); lcd.clear(); eta = false;*/

initialisation_pousse_seringue();

lcd.print(“PRET”); while (eta != true){

char touche = keypad.getKey();
if (touche == '#'){
  eta = true;
}

}

int sommemax = 0; int sommecour = 0; int diff[3]; int prec[3]; color(); for(int i=0; i<3; i++){

prec[i] = couleur[i];

}

lcd.clear(); digitalWrite(agitateur, HIGH); int compte=0; char touche = 't'; eta = false; while (eta != true){

char touche = keypad.getKey();
if (touche == '#'){
  eta = true;}
  
  Serial.print("color");   
  color();

  for(int i=0; i<3; i++){
    diff[i] = abs(prec[i]-couleur[i]);
  }
  for(int i=0;i<3; i++){
  prec[i] = couleur[i];
  }
  sommecour = diff[0] + diff[1] + diff[2];
  if (sommecour > sommemax){
    sommemax = sommecour;
  }
  /*lcd.clear();<)
  lcd.print("r:");
  lcd.print(couleur[0],DEC);
  lcd.print("b:");
  lcd.print(couleur[1],DEC);
  lcd.print("v:");
  lcd.print(couleur[2],DEC);    
  lcd.setCursor(0,1);
  lcd.print(compte);
  lcd.print(' ');
  lcd.print(sommecour);
  lcd.print(' ');
  lcd.print(sommemax);*/
  pousse_seringue(50);
  compte ++;
  
  }

lcd.clear(); lcd.print(“arret”); delay(1000); lcd.clear();

tofloat for all var float fcompte = (float) compte; char floatbuf[32]; make this at least big enough for the whole string

co.toCharArray(floatbuf, sizeof(floatbuf)); float fco = atof(floatbuf); vo.toCharArray(floatbuf, sizeof(floatbuf)); float fvo = atof(floatbuf); fc.toCharArray(floatbuf, sizeof(floatbuf)); float ffc = atof(floatbuf);

float mes = ffc*(fco*fcompte*10*vpas)/fvo; lcd.print(“resultat :”); lcd.setCursor(0,1); lcd.print(mes); lcd.print(“ mol/L”);

eta = false; while (eta != true){

char touche = keypad.getKey();
if (touche == '#'){
  eta = true;
  lcd.clear();
}

}

}

Projet titrimètre
Webographie
Carnet de bord
Réalisation du pousse seringue
Réalisation de l'agitation magnétique
Réalisation du capteur de changement de couleur
Réalisation du boitier

wiki/projets/titrimetre2/programmation.1462190553.txt.gz · Dernière modification: 2016/09/11 11:04 (modification externe)