Re: Projet thermoplieuse 2.0...
Publié : 19 févr. 2015, 10:22
Merci beaucoup, je passe en MP.
Mickaël
Mickaël
Code : Tout sélectionner
#include <LiquidCrystal.h>
#include <Servo.h>
//variables d'affichage
LiquidCrystal lcd(7, 8, 13, 10, 11, 12);
char strTemp[16] = "";
char strAng[16] = "";
//variables pour les BP
const int tpp = 2;
const int tpm = 4;
const int anp = 3;
const int anm = 5;
const int ok = 1;
int etat_bp;
int memoire_tpp = HIGH;
int memoire_tpm = HIGH;
int memoire_anp = HIGH;
int memoire_anm = HIGH;
//variables pour le temps et l'angle de pliage
int temp;
int ang;
//variables contacteur chauffe et servo
int chauffe = 6;
Servo servo;
void setup() {
pinMode(tpp, INPUT);
pinMode(tpm, INPUT);
pinMode(anp, INPUT);
pinMode(anm, INPUT);
pinMode(ok, INPUT);
pinMode(chauffe, OUTPUT);
servo.attach(9);
lcd.begin(16, 2);
lcd.setCursor(2,0);
lcd.print("THERMOPLIEUSE");
lcd.setCursor(5,1);
lcd.print("V 1.0");
delay(2000);
lcd.clear();
}
void loop() {
temp=0;
ang=0;
servo.write(0);
//Programation de la thermoplieuse
while(digitalRead(ok)==HIGH){
//incrémentation du temps
etat_bp = digitalRead(tpp);
if((etat_bp != memoire_tpp) && (etat_bp == LOW) && (temp > 0))
temp-=5;
memoire_tpp = etat_bp;
//decrementation du temps
etat_bp = digitalRead(tpm);
if((etat_bp != memoire_tpm) && (etat_bp == LOW) && (temp < 120))
temp+=5;
memoire_tpm = etat_bp;
//incrémentation de l'angle
etat_bp = digitalRead(anp);
if((etat_bp != memoire_anp) && (etat_bp == LOW) && (ang > 0))
ang-=10;
memoire_anp = etat_bp;
//decrementation de l'angle
etat_bp = digitalRead(anm);
if((etat_bp != memoire_anm) && (etat_bp == LOW) && (ang < 90))
ang+=10;
memoire_anm = etat_bp;
//On affiche le bousin
sprintf(strTemp,"Temps : %d sec",temp);
sprintf(strAng,"Angle : %d deg",ang);
lcd.setCursor(0,0);
lcd.print(strTemp);
lcd.setCursor(0,1);
lcd.print(strAng);
delay(20);
}
lcd.clear();
lcd.setCursor(2,0);
lcd.print("THERMOPLIAGE");
lcd.setCursor(4,1);
lcd.print("EN COURS");
//on démmarre la chauffe pendent
digitalWrite(chauffe, HIGH);
delay(1000*temp);
digitalWrite(chauffe, LOW);
//on démare le pliage
for(int pos = 0; pos < ang; pos ++)
{
servo.write(pos);
delay(15);
}
delay (10000);
}