Outils pour utilisateurs

Outils du site


fetitfilou

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentesRévision précédente
Prochaine révision
Révision précédente
Dernière révisionLes deux révisions suivantes
fetitfilou [2020/07/21 10:35] – [Detection] gazielfetitfilou [2020/07/21 12:06] gaziel
Ligne 2: Ligne 2:
  
 A la demande de Buz, création d'un petit filou géant, avec interaction. A la demande de Buz, création d'un petit filou géant, avec interaction.
- 
  
  
Ligne 9: Ligne 8:
   * faire de la lumière   * faire de la lumière
   * lancer une interjection de Buz   * lancer une interjection de Buz
 +
 +
  
 ====fabrication==== ====fabrication====
Ligne 20: Ligne 21:
  
 Module SR04 ultrason Module SR04 ultrason
- 
  
 {{::fetitfilou_sr04.jpg?nolink|}} {{::fetitfilou_sr04.jpg?nolink|}}
- 
  
 facile et efficace ! facile et efficace !
  
 librairie Ultrasonic d'Eric Simões librairie Ultrasonic d'Eric Simões
 +arduino=>SR04
  
 +5V=>VCC
 +
 +GND=>GND
 +
 +D2=>Echo
 +
 +D3=>Trig
  
  
Ligne 68: Ligne 75:
  
 ==== code ==== ==== code ====
 +
 <code python> <code python>
 +#include <Arduino.h>
  
 +//son
 +#include "DYPlayerArduino.h"
 +DY::Player player;
 +int son = 1;
 +
 +//detection SR04
 +#include <Ultrasonic.h>
 +Ultrasonic ultrasonic(2, 3);
 +int distance;
 +
 +// yeux
 #include <Servo.h> #include <Servo.h>
 Servo eye1; Servo eye1;
 Servo eye2; Servo eye2;
 +const byte EYE1PIN = 8; // broche servo Oeil
 +const byte EYE2PIN = 9; // broche servo Oei1
 +byte eye1Pos = 0;
 +byte eye2Pos = 0;
  
-int distance = 200; // distance en mm de detection du SR04 +//lumiere
-int duree = 30;   // durée de fonctionnement de l'animation+
  
-const byte POTDISPIN 0// broche analogique du potar de distance +const byte COLOR[8] {0b000, 0b100, 0b010, 0b001, 0b101, 0b011, 0b110, 0b111};
-const byte POTDELAYPIN = 1; // broche  analogique du delay de fonctionnement de l'animation+
  
-const byte RELAYPIN = 13; // pin du relais au besoin +/* Broches *
- +const byte PIN_LED_R 4
-const byte EYE1PIN 10// broche servo Oeil1 +const byte PIN_LED_G 5
-const byte EYE2PIN 11// broche servo Oeil1 +const byte PIN_LED_B 6
- +byte rvb = 0;
-const byte TRIGGER_PIN = 2; // Broche TRIGGER +
-const byte ECHO_PIN = 3;    // Broche ECHO +
-const unsigned long MEASURE_TIMEOUT = 25000UL; // 25ms = ~8m à 340m/s/* Constantes pour le timeout */ +
-const float SOUND_SPEED = 340.0 / 1000;/* Vitesse du son dans l'air en mm/us */ +
- +
-byte eye1Pos 0+
-byte eye2Pos = 0;+
  
  
 void setup() { void setup() {
-  // put your setup code here, to run once: +  //Serial.begin(9600);
-  Serial.begin(115200);+
  
-  randomSeed(analogRead(0)); +  player.begin(); 
- +  player.setVolume(20);
-  /* Initialise les broches */ +
-  pinMode(TRIGGER_PIN, OUTPUT); +
-  digitalWrite(TRIGGER_PIN, LOW); // La broche TRIGGER doit être à LOW au repos +
-  pinMode(ECHO_PIN, INPUT); +
-  Serial.println("SR04 OK");+
  
   eye1.attach(EYE1PIN);   eye1.attach(EYE1PIN);
   eye2.attach(EYE2PIN);   eye2.attach(EYE2PIN);
-  delay(100); 
-  eye1.write(eye1Pos); 
-  eye2.write(eye2Pos); 
-  Serial.println("Servo 1 et 2 ok"); 
-} 
  
-void anime() { +  randomSeed(analogRead(0));
- +
-  switch (duree) { +
- +
- +
- case 1 : // bas +
-    eye1Pos = 180 ; +
-    eye2Pos =  +
-    break; +
-  case 2 : // louche 1 +
-    eye1Pos = 90; +
-    eye2Pos = -90; +
-           break; +
-  case 3 : // louche 2 +
-    eye1Pos = -90  ; +
-    eye2Pos = 90  ; +
-  case 4 : // haut +
-    eye1Pos = 0  ; +
-    eye2Pos = 180  ; +
- +
-  default : //aleatoire +
-    eye1Pos = int(random(180)); +
-      eye2Pos = int(random(180)); +
-      break; +
-  }+
  
-  eye1.write(eye1Pos); +  pinMode(PIN_LED_R, OUTPUT); 
-  eye2.write(eye2Pos); +  pinMode(PIN_LED_G, OUTPUT); 
-  delay(100);+  pinMode(PIN_LED_B, OUTPUT); 
 +  displayColor(COLOR[7]);
 } }
  
  
-//renvois vrai si la distance en parametre est plus petite en mm +void loop() { 
-bool declanche( int distance) { +  //lecture de la distance en CM 
- +  distance = ultrasonic.read();
-  digitalWrite(TRIGGER_PIN, HIGH); +
-  delayMicroseconds(10); +
-  digitalWrite(TRIGGER_PIN, LOW); +
-  long mesure pulseIn(ECHO_PIN, HIGH, MEASURE_TIMEOUT); +
   delay(500);   delay(500);
-  if (mesure / 2.0 * SOUND_SPEED < distance) { 
-    return true; 
-  } 
-  else { 
-    return false; 
-  } 
  
  
  
 +  if (distance < 50) {
  
-}+    // couleur aleatoire 
 +    //rvb=byte(random(0,7); 
 +    displayColor(COLOR[int(random(0, 7))]); 
 +    delay(10); 
 +    //lecture d'un son aleatoire 
 +    son = int(random(1, 9)); 
 +    player.playSpecified(son); 
 +    delay(250); 
 +    displayColor(COLOR[int(random(0, 7))]);
  
-void loop() {+    // servo position aleatoire 
 +    eye1Pos = int(random(180)); 
 +    eye2Pos = int(random(180)); 
 +    
 +    eye1.write(eye1Pos); 
 +    eye2.write(eye2Pos); 
 +    delay(50); 
 +    displayColor(COLOR[int(random(0, 7))]); 
 +    //attente avant prochaine declanchement 
 +    delay(4000);
  
- +    // remise a off 
-  if (declanche(300)){ +    displayColor(COLOR[7]); 
- +    distance = 300;// forcage distance>50
-  anime(); +
-    // son +
-    // lumiere+
  
   }   }
 +}
  
 +/** Affiche une couleur */
 +void displayColor(byte color) {
  
 +  // Assigne l'état des broches
 +  // Version cathode commune
 +  //digitalWrite(PIN_LED_R, bitRead(color, 2));
 +  //digitalWrite(PIN_LED_G, bitRead(color, 1));
 +  //digitalWrite(PIN_LED_B, bitRead(color, 0));
 +  // Version anode commune
 +  digitalWrite(PIN_LED_R, !bitRead(color, 2));
 +  digitalWrite(PIN_LED_G, !bitRead(color, 1));
 +  digitalWrite(PIN_LED_B, !bitRead(color, 0));
 } }
 </code> </code>
  
fetitfilou.txt · Dernière modification : 2020/10/27 18:35 de serge