Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ************************************************
- // * Branchements *
- // ************************************************
- // D0 =>
- // D1 =>
- // D2 => Récepteur RF433
- // D3 => Phares
- // D4 => Direction Moteur 1
- // D5 => Contrôle moteur 1
- // D6 => Contrôle moteur 2
- // D7 => Direction Moteur 2
- // D8 => Feux arrière et intérieure Rouge
- // D9 => Feux de position Bleus
- // D10 => Servo Tourelle
- // D11 => Servo Pince
- // D12 => Oeil (projecteur tourelle)
- // D13 => Buzzer
- // ************************************************
- #include <RCSwitch.h>
- #include <Servo.h>
- Servo monServo;
- Servo maPince;
- RCSwitch mySwitch = RCSwitch();
- int rotationServo;
- long temporisation;
- int oeil = 12;
- int fArr = 8;
- int buzz = 13;
- int bleu = 9;
- bool etatOeil = 0;
- bool etatFArr = 0;
- bool etatBleu = 0;
- int lum = 0;
- int valBleu = 0;
- long temp;
- void setup() {
- Serial.begin(115200);
- mySwitch.enableReceive(0);
- pinMode(oeil, OUTPUT);
- pinMode(fArr, OUTPUT);
- pinMode(bleu, OUTPUT);
- pinMode(buzz, OUTPUT);
- monServo.attach(10);
- maPince.attach(11);
- temp = millis();;
- }
- void loop() {
- // Partie qui ne fonctionne pas :( **********************************************************************************
- if ((millis() - temp) >= 1500) { // on execute la suite toutes les 1.5 s
- Serial.println((millis() - temp)); // Debug ************************************************************
- if (analogRead(A0) != lum) { // on execute la suite que si la valeur de lum a changé
- lum = analogRead(A0); // lum prend la valeur lue en A0 (photorésistance)
- Serial.println(analogRead(A0)); // Debug ************************************************************
- valBleu = map(lum, 0, 1023, 255, 0); // valBleu prend la valeur de la conversion
- analogWrite(bleu, valBleu); // on allume les leds bleues de la valeur valBleu
- // Cela devrait, mais cela ne s'allume pas...
- Serial.println(valBleu); // Debug ************************************************************
- }
- temp = millis(); // on réinitialise le "chrono"
- }
- // ******************************************************************************************************************
- // Pourtant :
- // fonctionnait en D6 hier soir et un peu moins fort aujourd'hui (il fait jour)
- // (J'ai besoin du D6 pour le contrôle du futur moteur 2)
- // La led est bonne
- // La valeur valBleu varie bien, mais ne semble pas etre transmise à la led
- // tous les branchements sont vérifiés 200 fois :)
- // pas de faux contact
- // ******************************************************************************************************************
- if (mySwitch.available()) {
- if (mySwitch.getReceivedValue() >= 3000 && mySwitch.getReceivedValue() < 4000) {
- Serial.println (mySwitch.getReceivedValue());
- 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);
- delay (500);
- } else if (mySwitch.getReceivedValue() == 2003) {
- tone(buzz, 329, 200);
- delay (100);
- tone(buzz, 329, 200);
- delay (250);
- }
- mySwitch.resetAvailable();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement