Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ----- ----- ----- ----- ----- -----
- // Branchements
- // ----- ----- ----- ----- ----- -----
- // D0 =>
- // D1 =>
- // D2 => Récepteur RF433
- // D3 => Feux de position Bleus (4 LEDs)
- // D4 => Direction Moteur 1 (pas encore connecté)
- // D5 => Contrôle moteur 1 (pas encore connecté)
- // D6 => Contrôle moteur 2 (pas encore connecté)
- // D7 => Direction Moteur 2 (pas encore connecté)
- // D8 => Feux arrière et intérieure Rouge (2 LEDs)
- // D9 => Buzzer
- // D10 => Servo Tourelle(pas encore connecté)
- // D11 => Servo Pince(pas encore connecté)
- // D12 => Oeil (projecteur tourelle) (1 LED)
- // D13 => Phares (2 LEDs)
- // ----- ----- ----- ----- ----- -----
- #include <RCSwitch.h>
- #include <Servo.h>
- Servo monServo;
- Servo maPince;
- RCSwitch mySwitch = RCSwitch();
- int rotationServo;
- int rotationPince;
- long temporisation;
- const int bleu = 3;
- const int dirMot_1 = 4;
- const int contMot_1 = 5;
- const int contMot_2 = 6;
- const int dirMot_2 = 7;
- const int fArr = 8;
- const int phares = 9;
- const int tourelle = 10;
- const int pince = 11;
- const int oeil = 12;
- const int buzz = 13;
- bool etatOeil = 0;
- bool etatFArr = 0;
- bool etatBleu = 0;
- int lum = 0;
- int valBleu = 0;
- long temp;
- int seuilMoteur = 30;
- int vitesseMoteurDroit;
- int vitesseMoteurGauche;
- // Fonctions Moteurs
- // Gauche avance
- void M1_avance(char Speed)
- {
- digitalWrite(dirMot_1,HIGH);
- analogWrite(contMot_1,Speed);
- }
- // ----- ----- ----- ----- ----- -----
- // Droite avance
- void M2_avance(char Speed)
- {
- digitalWrite(dirMot_2,HIGH);
- analogWrite(contMot_2,Speed);
- }
- // ----- ----- ----- ----- ----- -----
- // Gauche recule
- void M1_recule(char Speed)
- {
- digitalWrite(dirMot_1,LOW);
- analogWrite(contMot_1,Speed);
- }
- // ----- ----- ----- ----- ----- -----
- // Droite recule
- void M2_recule(char Speed)
- {
- digitalWrite(dirMot_2,LOW);
- analogWrite(contMot_2,Speed);
- }
- // ----- ----- ----- ----- ----- -----
- // Gauche stop
- void M1_stop()
- {
- digitalWrite(dirMot_1,HIGH);
- analogWrite(contMot_1,0);
- }
- // ----- ----- ----- ----- ----- -----
- // Droite stop
- void M2_stop()
- {
- digitalWrite(dirMot_2,HIGH);
- analogWrite(contMot_2,0);
- }
- // ----- ----- ----- ----- ----- -----
- void setup() {
- Serial.begin(115200);
- mySwitch.enableReceive(0);
- pinMode(oeil, OUTPUT);
- pinMode(fArr, OUTPUT);
- pinMode(bleu, OUTPUT);
- pinMode(buzz, OUTPUT);
- pinMode(phares, OUTPUT);
- for (int i=4;i<=7;i++){
- pinMode(i, OUTPUT); //définit les port 4 à 7 en sortie
- }
- monServo.attach(tourelle);
- maPince.attach(pince);
- temp = millis();
- }
- void loop() {
- analogWrite(bleu, valBleu);
- if ((millis() - temp) >= 1500) { // on execute la suite toutes les 1.5 s
- lum = analogRead(A0); // lum prend la valeur lue en A0 (photorésistance)
- valBleu = map(lum, 0, 1023, 255, 0); // valBleu prend la valeur de la conversion
- Serial.println(valBleu);
- temp = millis();
- }
- if (mySwitch.available()) {
- if (mySwitch.getReceivedValue() >= 1000 && mySwitch.getReceivedValue() < 2000) {
- rotationPince = mySwitch.getReceivedValue() - 1000;
- maPince.write(rotationPince);
- delay (200);
- mySwitch.resetAvailable();
- } else if (mySwitch.getReceivedValue() >= 3000 && mySwitch.getReceivedValue() < 4000) {
- rotationServo = mySwitch.getReceivedValue() - 3000;
- monServo.write(rotationServo);
- delay (200);
- mySwitch.resetAvailable();
- } else if (mySwitch.getReceivedValue() == 2001) {
- if (etatOeil == 1) {
- etatOeil = 0;
- } else if (etatOeil == 0) {
- etatOeil = 1;
- }
- digitalWrite(oeil, etatOeil);
- delay (500);
- } else if (mySwitch.getReceivedValue() == 2002) {
- if (etatFArr == 1) {
- etatFArr = 0;
- } else if (etatFArr == 0) {
- etatFArr = 1;
- }
- digitalWrite(fArr, etatFArr);
- digitalWrite(phares, etatFArr);
- delay (500);
- } else if (mySwitch.getReceivedValue() == 2003) {
- /*tone(buzz, 329, 200);
- delay (250);
- tone(buzz, 329, 200);
- delay (250);*/
- tone(buzz, 440, 1000); //a
- delay (485);
- noTone(buzz);
- delay (15);
- tone(buzz, 440, 1000); //a
- delay (485);
- noTone(buzz);
- delay (15);
- tone(buzz, 440, 1000); //a
- delay (485);
- noTone(buzz);
- delay (15);
- tone(buzz, 349, 700); //f
- delay (335);
- noTone(buzz);
- delay (15);
- tone(buzz, 523, 300); //cH
- delay (185);
- noTone(buzz);
- delay (15);
- tone(buzz, 440, 1000); //a
- delay (485);
- noTone(buzz);
- delay (15);
- tone(buzz, 349, 700); //f
- delay (335);
- noTone(buzz);
- delay (15);
- tone(buzz, 523, 300); //cH
- delay (185);
- noTone(buzz);
- delay (15);
- tone(buzz, 440, 1300); //a
- delay (750);
- noTone(buzz);
- } else if (mySwitch.getReceivedValue() >= 4000 && mySwitch.getReceivedValue() < 5000) {
- vitesseMoteurDroit = mySwitch.getReceivedValue() - 4125;
- if (vitesseMoteurDroit > seuilMoteur){
- M2_avance (vitesseMoteurDroit);
- mySwitch.resetAvailable();
- } else if (vitesseMoteurDroit < seuilMoteur*(-1)){
- vitesseMoteurDroit *= -1;
- M2_recule (vitesseMoteurDroit);
- mySwitch.resetAvailable();
- }else if (vitesseMoteurDroit < seuilMoteur && vitesseMoteurDroit > seuilMoteur*(-1)){
- M2_stop ();
- mySwitch.resetAvailable();
- }
- } else if (mySwitch.getReceivedValue() >= 5000 && mySwitch.getReceivedValue() < 6000) {
- vitesseMoteurGauche = mySwitch.getReceivedValue() - 5125;
- if (vitesseMoteurGauche > seuilMoteur){
- M1_avance (vitesseMoteurGauche);
- mySwitch.resetAvailable();
- } else if (vitesseMoteurGauche < seuilMoteur*(-1)){
- vitesseMoteurGauche *= -1;
- M1_recule (vitesseMoteurGauche);
- mySwitch.resetAvailable();
- } else if (vitesseMoteurGauche < seuilMoteur && vitesseMoteurGauche > seuilMoteur*(-1)){
- M1_stop ();
- mySwitch.resetAvailable();
- }
- }
- mySwitch.resetAvailable();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement