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

Prochaine révision
Révision précédente
fetitfilou [2020/02/17 09:29] – créée gazielfetitfilou [2020/10/27 18:35] (Version actuelle) – ↷ Liens modifiés en raison d'un déplacement. serge
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 17: Ligne 18:
 2 servos 2 servos
  
 +====Detection====
  
-bruit et Lumière en attente+Module SR04 ultrason
  
-==== code ==== +{{media_04:fetitfilou_sr04.jpg?nolink|}}
-<WRAP center round box 90%>+
  
 +facile et efficace !
  
-#include <Servo.h> +librairie Ultrasonic d'Eric Simões 
-Servo eye1; +arduino=>SR04
-Servo eye2;+
  
-int distance 200; // distance en mm de detection du SR04 +5V=>VCC
-int duree = 30;   // durée de fonctionnement de l'animation+
  
-const byte POTDISPIN 0; // broche analogique du potar de distance +GND=>GND
-const byte POTDELAYPIN = 1; // broche  analogique du delay de fonctionnement de l'animation+
  
-const byte RELAYPIN 13; // pin du relais au besoin+D2=>Echo
  
-const byte EYE1PIN 10; // broche servo Oeil1 +D3=>Trig
-const byte EYE2PIN = 11; // broche servo Oeil1+
  
-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; +====Bruit====
-byte eye2Pos 0;+
  
 +utilisation d'un "DY Player" , une carte pour lecteur MP3 DIY .
 +{{media_04:fetitfilou_dyplayer.jpg?nolink|}}
 +module DY-SV5W  carte avec lecteur microSD et ampli 5W intégré
 +utilisation en Mode UART ( envoie de commande par le port TX/RX série de l'arduino)=> permet 255 sons facilement
  
-void setup() { +Sans prise de tête avec la librairie [[https://github.com/SnijderC/dyplayer|dyplayer de SnijderC]]
-  // put your setup code here, to run once: +
-  Serial.begin(115200);+
  
-  randomSeed(analogRead(0));+juste 3 fils :
  
-  /* Initialise les broches */ +arduino=>DFplayer
-  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); +5V=>+5V
-  eye2.attach(EYE2PIN); +
-  delay(100); +
-  eye1.write(eye1Pos); +
-  eye2.write(eye2Pos); +
-  Serial.println("Servo 1 et 2 ok"); +
-}+
  
-void anime() {+GND=>-5V
  
-  switch (duree) {+D1/TX=>IO1/RX
  
  
- case 1 : // bas +====Lumière===
-    eye1Pos 180 ; +
-    eye2Pos  0 ; +
-    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 +juste une LED RGB !
-    eye1Pos = int(random(180)); +
-      eye2Pos = int(random(180)); +
-      break; +
-  }+
  
-  eye1.write(eye1Pos); +arduino=>LED
-  eye2.write(eye2Pos); +
-  delay(100); +
-}+
  
 +5V=>V
  
-//renvois vrai si la distance en parametre est plus petite en mm +D4=>R
-bool declanche( int distance) {+
  
-  digitalWrite(TRIGGER_PIN, HIGH); +D5=>B
-  delayMicroseconds(10); +
-  digitalWrite(TRIGGER_PIN, LOW); +
-  long mesure pulseIn(ECHO_PIN, HIGH, MEASURE_TIMEOUT);+
  
-  delay(500); +D6=>G
-  if (mesure / 2.0 * SOUND_SPEED < distance) { +
-    return true; +
-  } +
-  else { +
-    return false; +
-  }+
  
  
  
 +==== code ====
  
 +<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>
 +Servo eye1;
 +Servo eye2;
 +const byte EYE1PIN = 8; // broche servo Oeil
 +const byte EYE2PIN = 9; // broche servo Oei1
 +byte eye1Pos = 0;
 +byte eye2Pos = 0;
 +
 +//lumiere
 +
 +const byte COLOR[8] = {0b000, 0b100, 0b010, 0b001, 0b101, 0b011, 0b110, 0b111};
 +
 +/* Broches */
 +const byte PIN_LED_R = 4;
 +const byte PIN_LED_G = 5;
 +const byte PIN_LED_B = 6;
 +byte rvb = 0;
 +
 +
 +void setup() {
 +  //Serial.begin(9600);
 +
 +  player.begin();
 +  player.setVolume(20);
 +
 +  eye1.attach(EYE1PIN);
 +  eye2.attach(EYE2PIN);
 +
 +  randomSeed(analogRead(0));
 +
 +  pinMode(PIN_LED_R, OUTPUT);
 +  pinMode(PIN_LED_G, OUTPUT);
 +  pinMode(PIN_LED_B, OUTPUT);
 +  displayColor(COLOR[7]);
 } }
 +
  
 void loop() { void loop() {
 +  //lecture de la distance en CM
 +  distance = ultrasonic.read();
 +  delay(500);
  
  
-  if (declanche(300)){ 
  
-  anime(); +  if (distance < 50) { 
-    // son + 
-    // lumiere+    // 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))]); 
 + 
 +    // 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 
 +    displayColor(COLOR[7]); 
 +    distance = 300;// forcage distance>50
  
   }   }
 +}
  
 +/** 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));
 } }
-</WRAP>+</code>
  
fetitfilou.1581931788.txt.gz · Dernière modification : de gaziel