Outils pour utilisateurs

Outils du site


wiki:projets:polarimetre-materiel-programmation
  • *Voici la version (quasi-)définitive du programme du polarimètre (deux Arduino et deux motor shield): Arduino maitre: <code c> #include <Stepper.h> #include <LiquidCrystal.h> const int stepsPerRevolution = 200; int photoPin = A5; int photocellREADING; int Comm = 7; int alpha; int StepCount = 0; int CUVE = 1; Stepper analyzer(200, 12, 13); LiquidCrystal lcd(12, 11, 5, 4, 3, 2); const int pwmA = 3; const int pwmB = 11; const int brakeA = 9; const int brakeB = 8; const int dirA = 12; const int dirB = 13; void setup() { Serial.begin(9600); lcd.begin(16, 1); pinMode(Comm, OUTPUT); pinMode(pwmA, OUTPUT); pinMode(pwmB, OUTPUT); pinMode(brakeA, OUTPUT); pinMode(brakeB, OUTPUT); digitalWrite(pwmA, HIGH); digitalWrite(pwmB, HIGH); digitalWrite(brakeA, LOW); digitalWrite(brakeB, LOW); analyzer.setSpeed(50); Serial.println(“Cuve numero :”), Serial.print(CUVE); Serial.println(“ ”); Serial.println(“ ”); Serial.println(“ ”); } void loop() { delay(1000); photocellREADING= analogRead(photoPin); Serial.println(photocellREADING); if(CUVE < 4){ if(photocellREADING > 750){ delay(1000); analyzer.step(10); digitalWrite(Comm, LOW); StepCount = StepCount + 10; } else{ if(photocellREADING > 500){ delay(1000); analyzer.step(5); digitalWrite(Comm, LOW); StepCount = StepCount + 5; } else{ if(photocellREADING > 200){ delay(1000); analyzer.step(2); digitalWrite(Comm, LOW); StepCount = StepCount + 2; } else{ if(photocellREADING > 100){ delay(1000); analyzer.step(1); digitalWrite(Comm, LOW); StepCount = StepCount + 1; } else{ alpha = StepCount * 1.8; Serial.println(“ ”); Serial.println(“Angle alpha de la cuve numero ”); Serial.print(CUVE); Serial.println(“=”); Serial.println(“ ”); Serial.print(alpha); lcd.setCursor(0, 0); lcd.print(alpha); delay(3000); analyzer.step(-StepCount); StepCount = 0; digitalWrite(Comm, HIGH); delay(200); digitalWrite(Comm,LOW); delay(3000); CUVE = CUVE + 1; Serial.println(“ ”); Serial.println(“ ”); Serial.println(“ ”); Serial.println(“Cuve numero :”), Serial.print(CUVE); Serial.println(“ ”); Serial.println(“ ”); Serial.println(“ ”); } } } } } else{ if(CUVE = 4){ if(photocellREADING > 750){ delay(1000); analyzer.step(10); digitalWrite(Comm, LOW); StepCount = StepCount + 10; } else{ if(photocellREADING > 500){ delay(1000); analyzer.step(5); digitalWrite(Comm, LOW); StepCount = StepCount + 5; } else{ if(photocellREADING > 200){ delay(1000); analyzer.step(2); digitalWrite(Comm, LOW); StepCount = StepCount + 2; } else{ if(photocellREADING > 100){ delay(1000); analyzer.step(1); digitalWrite(Comm, LOW); StepCount = StepCount + 1; } else{ alpha = StepCount * 1.8; Serial.println(“ ”); Serial.println(“Angle alpha de la cuve numero ”); Serial.print(CUVE); Serial.println(“=”); Serial.println(“ ”); Serial.print(alpha); lcd.setCursor(0, 0); lcd.print(alpha); delay(3000); analyzer.step(-StepCount); StepCount = 0; digitalWrite(Comm, HIGH); delay(200); digitalWrite(Comm,LOW); delay(3000); delay(5000); CUVE = 1; Serial.println(“ ”); Serial.println(“ ”); Serial.println(“ ”); Serial.println(“Cuve numero :”), Serial.print(CUVE); Serial.println(“ ”); Serial.println(“ ”); Serial.println(“ ”); } } } } } } } </code> Arduino esclave: <code c> #include <Stepper.h> int Comm2 = 7; byte Trigger; Stepper cuve(200, 12,13); const int pwmC = 3; const int pwmD = 11; const int brakeC = 9; const int brakeD = 8; const int dirC = 12; const int dirD = 13; void setup() { Serial.begin(9600); pinMode(Comm2, INPUT); pinMode(pwmC, OUTPUT); pinMode(pwmD, OUTPUT); pinMode(brakeC, OUTPUT); pinMode(brakeD, OUTPUT); digitalWrite(pwmC, HIGH); digitalWrite(pwmD, HIGH); digitalWrite(brakeC, LOW); digitalWrite(brakeD, LOW); cuve.setSpeed(50); } void loop() { Trigger = digitalRead(Comm2); Serial.println(Trigger); if(Trigger <1) { Serial.println(“laser”); delay(200); } else { Serial.print(“rotate”); cuve.step(200); delay(3000); } } </code> Programme maitre version 2 <code c> #include <Stepper.h> #include <LiquidCrystal.h> const int stepsPerRevolution = 200; int photoPin = A5; int photocellREADING; int Comm = 7; int alpha; int StepCount = 0; int CUVE = 1; int COUVE; Stepper analyzer(200, 12, 13); LiquidCrystal lcd(10, 7, 6, 5, 4, 2); const int pwmA = 3; const int pwmB = 11; const int brakeA = 9; const int brakeB = 8; const int dirA = 12; const int dirB = 13; void setup() { Serial.begin(9600); lcd.begin(16, 2); pinMode(Comm, OUTPUT); pinMode(pwmA, OUTPUT); pinMode(pwmB, OUTPUT); pinMode(brakeA, OUTPUT); pinMode(brakeB, OUTPUT); digitalWrite(pwmA, HIGH); digitalWrite(pwmB, HIGH); digitalWrite(brakeA, LOW); digitalWrite(brakeB, LOW); analyzer.setSpeed(50); Serial.println(“Cuve numero 1”); Serial.println(“ ”); Serial.println(“ ”); Serial.println(“ ”); } void loop() { delay(1000); photocellREADING= analogRead(photoPin); Serial.println(photocellREADING); if(CUVE == 1){ lcd.setCursor(0, 0); lcd.print(“Cuve numero”); lcd.setCursor(12, 0); lcd.print(CUVE); if(photocellREADING > 750){ delay(1000); analyzer.step(10); digitalWrite(Comm, LOW); StepCount = StepCount + 10; } else{ if(photocellREADING > 500){ delay(1000); analyzer.step(5); digitalWrite(Comm, LOW); StepCount = StepCount + 5; } else{ if(photocellREADING > 200){ delay(1000); analyzer.step(2); digitalWrite(Comm, LOW); StepCount = StepCount + 2; } else{ if(photocellREADING > 100){ delay(1000); analyzer.step(1); digitalWrite(Comm, LOW); StepCount = StepCount + 1; } else{ alpha = StepCount * 1.8; Serial.println(“ ”); Serial.println(“Angle alpha de la cuve numero 1 =”); Serial.println(“ ”); Serial.print(alpha); lcd.setCursor(0, 1); lcd.print(alpha); analyzer.step(-StepCount); StepCount = 0; digitalWrite(Comm, HIGH); delay(200); digitalWrite(Comm,LOW); delay(3000); lcd.clear(); CUVE = CUVE + 1; Serial.println(“ ”); Serial.println(“ ”); Serial.println(“ ”); Serial.println(“Cuve numero 2”); Serial.println(“ ”); Serial.println(“ ”); Serial.println(“ ”); } } } } } else{ if(CUVE == 2){ lcd.setCursor(0, 0); lcd.print(“Cuve numero 2”); if(photocellREADING > 800){ delay(1000); analyzer.step(10); digitalWrite(Comm, LOW); StepCount = StepCount + 10; } else{ alpha = StepCount * 1.8; lcd.setCursor(0, 1); lcd.print(alpha); analyzer.step(-StepCount); StepCount = 0; digitalWrite(Comm,LOW); delay(3000); lcd.clear(); CUVE = CUVE + 1; } } else{ if(CUVE == 3){ lcd.setCursor(0, 0); lcd.print(“Cuve numero 2”); if(photocellREADING > 750){ delay(1000); analyzer.step(10); digitalWrite(Comm, LOW); StepCount = StepCount + 10; } else{ if(photocellREADING > 500){ delay(1000); analyzer.step(5); digitalWrite(Comm, LOW); StepCount = StepCount + 5; } else{ if(photocellREADING > 200){ delay(1000); analyzer.step(2); digitalWrite(Comm, LOW); StepCount = StepCount + 2; } else{ if(photocellREADING > 100){ delay(1000); analyzer.step(1); digitalWrite(Comm, LOW); StepCount = StepCount + 1; } else{ alpha = StepCount * 1.8; Serial.println(“ ”); Serial.println(“Angle alpha de la cuve numero 2 =”); Serial.println(“ ”); Serial.print(alpha); lcd.setCursor(0, 1); lcd.print(alpha); analyzer.step(-StepCount); StepCount = 0; digitalWrite(Comm, HIGH); delay(200); digitalWrite(Comm,LOW); delay(3000); lcd.clear(); CUVE = CUVE + 1; Serial.println(“ ”); Serial.println(“ ”); Serial.println(“ ”); Serial.println(“Cuve numero 3”); Serial.println(“ ”); Serial.println(“ ”); Serial.println(“ ”); } } } } } else{ if(CUVE == 4){ lcd.setCursor(0, 0); lcd.print(“Cuve numero 2”); if(photocellREADING > 800){ delay(1000); analyzer.step(10); digitalWrite(Comm, LOW); StepCount = StepCount + 10; } else{ alpha = StepCount * 1.8; lcd.setCursor(0, 1); lcd.print(alpha); analyzer.step(-StepCount); StepCount = 0; digitalWrite(Comm,LOW); delay(3000); lcd.clear(); CUVE = CUVE + 1; } } else{ if(CUVE == 5){ lcd.setCursor(0, 0); lcd.print(“Cuve numero 3”); if(photocellREADING > 750){ delay(1000); analyzer.step(10); digitalWrite(Comm, LOW); StepCount = StepCount + 10; } else{ if(photocellREADING > 500){ delay(1000); analyzer.step(5); digitalWrite(Comm, LOW); StepCount = StepCount + 5; } else{ if(photocellREADING > 200){ delay(1000); analyzer.step(2); digitalWrite(Comm, LOW); StepCount = StepCount + 2; } else{ if(photocellREADING > 100){ delay(1000); analyzer.step(1); digitalWrite(Comm, LOW); StepCount = StepCount + 1; } else{ alpha = StepCount * 1.8; Serial.println(“ ”); Serial.println(“Angle alpha de la cuve numero 3 =”); Serial.println(“ ”); Serial.print(alpha); lcd.setCursor(0, 1); lcd.print(alpha); delay(3000); lcd.clear(); analyzer.step(-StepCount); StepCount = 0; digitalWrite(Comm, HIGH); delay(200); digitalWrite(Comm,LOW); delay(3000); CUVE = CUVE + 1; delay(5000); Serial.println(“ ”); Serial.println(“ ”); Serial.println(“ ”); Serial.println(“Cuve numero 4”); Serial.println(“ ”); Serial.println(“ ”); Serial.println(“ ”); } } } } } else{ if(CUVE == 6){ lcd.setCursor(0, 0); lcd.print(“Cuve numero 2”); if(photocellREADING > 800){ delay(1000); analyzer.step(10); digitalWrite(Comm, LOW); StepCount = StepCount + 10; } else{ alpha = StepCount * 1.8; lcd.setCursor(0, 1); lcd.print(alpha); analyzer.step(-StepCount); StepCount = 0; digitalWrite(Comm,LOW); delay(3000); lcd.clear(); CUVE = CUVE + 1; } } else{ if(CUVE == 7){ lcd.setCursor(0, 0); lcd.print(“Cuve numero 4”); if(photocellREADING > 750){ delay(1000); analyzer.step(10); digitalWrite(Comm, LOW); StepCount = StepCount + 10; } else{ if(photocellREADING > 500){ delay(1000); analyzer.step(5); digitalWrite(Comm, LOW); StepCount = StepCount + 5; } else{ if(photocellREADING > 200){ delay(1000); analyzer.step(2); digitalWrite(Comm, LOW); StepCount = StepCount + 2; } else{ if(photocellREADING > 100){ delay(1000); analyzer.step(1); digitalWrite(Comm, LOW); StepCount = StepCount + 1; } else{ alpha = StepCount * 1.8; Serial.println(“ ”); Serial.println(“Angle alpha de la cuve numero 4 =”); Serial.println(“ ”); Serial.print(alpha); lcd.setCursor(0, 1); lcd.print(alpha); delay(3000); lcd.clear(); analyzer.step(-StepCount); StepCount = 0; digitalWrite(Comm, HIGH); delay(200); digitalWrite(Comm,LOW); delay(3000); COUVE = 1; CUVE = CUVE + 1; Serial.println(“ ”); Serial.println(“ ”); Serial.println(“ ”); Serial.println(“Cuve numero 1”), Serial.println(“ ”); Serial.println(“ ”); Serial.println(“ ”); } } } } } else{ if(COUVE == 1){ lcd.setCursor(0, 0); lcd.print(“Cuve numero 2”); if(photocellREADING > 800){ delay(1000); analyzer.step(10); digitalWrite(Comm, LOW); StepCount = StepCount + 10; } else{ alpha = StepCount * 1.8; lcd.setCursor(0, 1); lcd.print(alpha); analyzer.step(-StepCount); StepCount = 0; digitalWrite(Comm,LOW); delay(3000); lcd.clear(); CUVE = 1; COUVE = 0; } } } } } } } } } } </code> ———————————— Programme esclave <code c> #include <Stepper.h> int Comm2 = 7; byte Trigger; Stepper cuve(200, 12,13); const int pwmC = 3; const int pwmD = 11; const int brakeC = 9; const int brakeD = 8; const int dirC = 12; const int dirD = 13; void setup() { Serial.begin(9600); pinMode(Comm2, INPUT); pinMode(pwmC, OUTPUT); pinMode(pwmD, OUTPUT); pinMode(brakeC, OUTPUT); pinMode(brakeD, OUTPUT); digitalWrite(pwmC, HIGH); digitalWrite(pwmD, HIGH); digitalWrite(brakeC, LOW); digitalWrite(brakeD, LOW); cuve.setSpeed(50); } void loop() { Trigger = digitalRead(Comm2); Serial.println(Trigger); if(Trigger <1) { Serial.println(“laser”); delay(200); } else { Serial.print(“rotate”); cuve.step(200); delay(3000); } } </code>
wiki/projets/polarimetre-materiel-programmation.txt · Dernière modification: 2020/10/05 16:39 (modification externe)